moved data to JSON

fruitual
log 2 years ago
parent 0b5baef751
commit f7c50fc860

@ -0,0 +1,112 @@
# A Void
# by Gorgs Prc
#
# Adaptation to IF by log
# ------------------
# Variables
# ------------------
import random
import os
import sys
import json
from time import sleep
import voidfunc
with open('voiddata.json', 'r') as f:
voiddata = json.load(f)
rooms = ["room", "island", "bar"]
class bcolors:
BLUE = '\033[94m'
CYAN = '\033[96m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
MAGENTA = '\x1b[35m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
# Start of book
# ------------------
os.system('clear') #this needs to be cls for windows
print(bcolors.CYAN + "-"*80 + "\n" + "-"*80 + "\n" + "-"*80 + "\n")
sleep(0.5)
print("""
_ _
__ _ __ _____ (_) __| |
/ _` | \ \ / / _ \| |/ _` |
| (_| | \ V / (_) | | (_| |
\__,_| \_/ \___/|_|\__,_|
by Gorgs Prc
Push to start
""")
sleep(0.5)
print("-"*80 + "\n" + "-"*80 + "\n" + "-"*80 + "\n" + bcolors.ENDC)
input()
os.system('clear') #this needs to be cls for windows
sleep(1)
print(bcolors.CYAN + "-"*80 +
"""
:::
:+:+:
+:+
+#+
+#+
#+#
#######
_ _ _ _ _ _ _ _ _
/ \ / \ / \ / \ / \ / \ / \ / \ / \
( A | n | t | o | n ) ( V | o | w | l )
\_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/
""")
print("-"*80)
sleep(1)
voidfunc.delayPrint("\n" + " "*40 + voiddata[voidfunc.current_room]["intro"])
print("-"*79 + bcolors.ENDC)
sleep(1)
voidfunc.delayPrint(voiddata[voidfunc.current_room]["message"])
while True:
# Wait for user input
reply = input()
# End the game if all rooms have been explored
if len(rooms) == 0:
voidfunc.gameover()
break
# End the room if all items have been interacted with
if any(s not in voidfunc.viewedthings for s in voiddata[voidfunc.current_room]["items"]):
pass
else:
voidfunc.nextroom(rooms)
# Do functions based on reply
if "exit" in reply:
voidfunc.gameover()
break
elif "e" in reply or len(voiddata[voidfunc.current_room]["items"]) == 0:
voidfunc.nextroom(rooms)
elif "port" in reply and "flip" in reply:
voidfunc.portflip(rooms)
elif any(word in reply.split() for word in voiddata[voidfunc.current_room]["items"]):
word = next((s for s in reply.split() if s in voiddata[voidfunc.current_room]["items"]), None)
voidfunc.interact(word)
elif any(s in reply for s in ["look", "scan", "watch", "study", "spot", "spy", "analysis", "probing", "grill", voidfunc.current_room]):
voidfunc.look()
else:
voidfunc.delayPrint(voidfunc.defaultReply())

@ -0,0 +1,7 @@
import json
with open('voiddata.json', 'r') as f:
voiddata = json.load(f)
# Output: {'name': 'Bob', 'languages': ['English', 'French']}
print(voiddata["bar"]["name"])

@ -0,0 +1,81 @@
import json
# Data to be written
roomthings = {}
roomthings["room"]={"bookstand": "To his right is a mahogany stand on which sit 26 books - on which, I should say, 26 books normally ought to sit, but, as always, a book is missing, a book with an inscription, '5', on its flap. Nothing about this stand, though, looks at all abnormal or out of proportion, no hint of a missing publication, no filing card or 'ghost', as librarians quaintly call it, no conspicuous gap or blank",
"windowsill": "Crawling across his windowsill is a tiny animal, indigo and saffron in colour, not a cockroach, not a blowfly, but a kind of wasp, laboriously dragging a sugar crumb along with it. Hoping to crush it with a casual blow, Vowl lifts up his right hand; but it abruptly flaps its wings, flying off without giving its assailant an opportunity to do it any harm.",
"door": "Padding into his bathroom, Vowl dabs at his brow and throat with a damp cloth. Back to his room.",
"visiting-card": "Laid out languorously, all day long, on a couch or on a sofa, or on occasion rocking to and fro in his rocking chair, stubbornly trying to copy out on an old visiting-card that indistinct motif that had sprung at him from his rug, as frail as an infant but not now, thanks to Cochin's surgical skills, in all that much physical pain, our protagonist starts hallucinating, blowing his mind. ",
"rug": "His mind runs riot. Lost in thought, scrutinising his rug, Vowl starts imagining 5, 6, 26 distinct visual combinations, absorbing but also insubstantial, as though an artist's rough drafts but of what? - that, possibly, which a psychiatrist would call Jungian slips, an infinity of dark, mythic, anonymous portraits flitting through his brain, as it burrows for a solitary, global signal that might satisfy his natural human lust for signification both instant and lasting, a signal that might commandingly stand out from this chain of discontinuous links, this miasma of shadowy tracings, all of which, or so you would think, ought to knit up to form a kind of paradigmatic configuration, of which such partial motifs can furnish only anagrams and insipid approximations: \n a body crumpling up, a hoodlum, a portrait of an artist as a young dog; \n a bullock, a Bogartian falcon, a brooding blackbird; \n an arthritic old man; \n a sigh;"}
roomthings["island"]={
"stick": "At dusk, using a sharp rock, Ishmail cuts a notch on a stick (to tick off his first night as a castaway); and, with a total of 20 such cuts, constructs a hut, a sort of impromptu shack, with a door, four walls, and flooring and roofing built out of mud. With no matchsticks at hand, though, his food is invariably raw.",
"compound": "It was built, circa 1930, in a crypto-rococo fashion imitating, variously, a pink-icing casino in Monaco, a bungalow on a Malayan plantation, a colonialist villa, an ultra-chic condominium in Miami and Tara from GWTW. ",
"cushion": " a numb, downcast, haggard Ishmail withdraws his hand. What, again, occurs is that this cushion, say - a thing normally as soft and downy as a baby's bottom - is, to his touch, now a hard, cold, compact block, as rock-hard as a diamond, as though part of a shadowy twin world consubstantial with Ishmail's own but caught through a glass darkly, a living mirror of our own world and just as cold, shiny and insular as a mirror. "}
roomthings["bar"]={
"barman": """BARMAN (who knows a thing or two): Morning, mon Commandant.
COMMANDANT (calming down now that, although in mufti, his rank is plain to this barman): Ah, good morning to you, my boy, good morning!
BARMAN (who has a slight but distinct hint of Oirishry about him): And what, pray, can I do for you, sir? Your wish is my command.
COMMANDANT (licking his lips): You know what I fancy most of all - a port-flip.
BARMAN (frowning)-. What? """,
"port": """COMMANDANT (furiously pointing in front of him): Now look, that's port, isn't it?
BARMAN (in agony): Uh huh . . . but. . .
COMMANDANT (livid): So? So? And (pointing again) that's an. . . """}
# -------------------
room = {
"name": "room",
"message": """
Incurably insomniac, Anton Vowl turns on a light. According to his watch it's only 12.20. With a loud and languorous sigh Vowl sits up, stuffs a pillow at his back, draws his quilt up around his chin, picks up his whodunit and idly scans a paragraph or two; but, judging its plot impossibly difficult to follow in his condition, its vocabulary too whimsically multisyllabic for comfort, throws it away in disgust.
""",
"death": """
It's all in vain. His subconscious vision starts buzzing around him again, buzzing around and within him, choking and suffocating him.""",
"intro":"""1
Which at first calls to mind a probably familiar story of a drunk man waking up with his brain in a whirl.""",
"items": roomthings["room"]
}
island = {
"name": "island",
"message": """
But six days go past, and his unusually robust constitution allows him finally to sit up and look around him. Our protagonist is now disturbingly skinny but can still, if with difficulty, climb out of his pit a pit that was almost his tomb. So Ishmail starts living again.""",
"death": """
At which point Ishmail falls victim to hallucinations, possibly from consuming a poisonous black mushroom or having had too much to drink; or, why not, from having shrunk so much as to vanish wholly from sight""",
"intro":"""2
In which luck, God's alias and alibi, plays a callous trick on a suitor cast away on an island.""",
"items": roomthings["island"]
}
bar = {
"name": "bar",
"message": """
MAN, sitting down and barking (with gruff and, as you might say, military incivility): Barman! """,
"death":"""BARMAN (abruptly dying): Aaaaaaah! Shhhhhhh . . . R.I.P.
COMMANDANT (about to go but first noticing his body): What a storm in a port-flip!
Which is what you might call adding insult to injury.""",
"intro": """3
"Oh, how idiotic," murmurs Vowl. But just as idiotic, now, is his vision of a man going into a bar: """,
"items": roomthings["bar"]
}
placedata = {"room":room, "island":island, "bar":bar}
# Serializing json
json_messages = json.dumps(placedata, indent=4)
# Writing to sample.json
with open("voiddata.json", "w") as outfile:
outfile.write(json_messages)

@ -0,0 +1,6 @@
{
"name": "sathiyajith",
"rollno": 56,
"cgpa": 8.6,
"phonenumber": "9976770500"
}

@ -0,0 +1,36 @@
{
"room": {
"name": "room",
"message": "\nIncurably insomniac, Anton Vowl turns on a light. According to his watch it's only 12.20. With a loud and languorous sigh Vowl sits up, stuffs a pillow at his back, draws his quilt up around his chin, picks up his whodunit and idly scans a paragraph or two; but, judging its plot impossibly difficult to follow in his condition, its vocabulary too whimsically multisyllabic for comfort, throws it away in disgust. \n",
"death": "\nIt's all in vain. His subconscious vision starts buzzing around him again, buzzing around and within him, choking and suffocating him.",
"intro": "1\n \nWhich at first calls to mind a probably familiar story of a drunk man waking up with his brain in a whirl.",
"items": {
"bookstand": "To his right is a mahogany stand on which sit 26 books - on which, I should say, 26 books normally ought to sit, but, as always, a book is missing, a book with an inscription, '5', on its flap. Nothing about this stand, though, looks at all abnormal or out of proportion, no hint of a missing publication, no filing card or 'ghost', as librarians quaintly call it, no conspicuous gap or blank",
"windowsill": "Crawling across his windowsill is a tiny animal, indigo and saffron in colour, not a cockroach, not a blowfly, but a kind of wasp, laboriously dragging a sugar crumb along with it. Hoping to crush it with a casual blow, Vowl lifts up his right hand; but it abruptly flaps its wings, flying off without giving its assailant an opportunity to do it any harm.",
"door": "Padding into his bathroom, Vowl dabs at his brow and throat with a damp cloth. Back to his room.",
"visiting-card": "Laid out languorously, all day long, on a couch or on a sofa, or on occasion rocking to and fro in his rocking chair, stubbornly trying to copy out on an old visiting-card that indistinct motif that had sprung at him from his rug, as frail as an infant but not now, thanks to Cochin's surgical skills, in all that much physical pain, our protagonist starts hallucinating, blowing his mind. ",
"rug": "His mind runs riot. Lost in thought, scrutinising his rug, Vowl starts imagining 5, 6, 26 distinct visual combinations, absorbing but also insubstantial, as though an artist's rough drafts but of what? - that, possibly, which a psychiatrist would call Jungian slips, an infinity of dark, mythic, anonymous portraits flitting through his brain, as it burrows for a solitary, global signal that might satisfy his natural human lust for signification both instant and lasting, a signal that might commandingly stand out from this chain of discontinuous links, this miasma of shadowy tracings, all of which, or so you would think, ought to knit up to form a kind of paradigmatic configuration, of which such partial motifs can furnish only anagrams and insipid approximations: \n a body crumpling up, a hoodlum, a portrait of an artist as a young dog; \n a bullock, a Bogartian falcon, a brooding blackbird; \n an arthritic old man; \n a sigh;"
}
},
"island": {
"name": "island",
"message": "\nBut six days go past, and his unusually robust constitution allows him finally to sit up and look around him. Our protagonist is now disturbingly skinny but can still, if with difficulty, climb out of his pit \u2014 a pit that was almost his tomb. So Ishmail starts living again.",
"death": "\nAt which point Ishmail falls victim to hallucinations, possibly from consuming a poisonous black mushroom or having had too much to drink; or, why not, from having shrunk so much as to vanish wholly from sight",
"intro": "2\n \nIn which luck, God's alias and alibi, plays a callous trick on a suitor cast away on an island.",
"items": {
"stick": "At dusk, using a sharp rock, Ishmail cuts a notch on a stick (to tick off his first night as a castaway); and, with a total of 20 such cuts, constructs a hut, a sort of impromptu shack, with a door, four walls, and flooring and roofing built out of mud. With no matchsticks at hand, though, his food is invariably raw.",
"compound": "It was built, circa 1930, in a crypto-rococo fashion imitating, variously, a pink-icing casino in Monaco, a bungalow on a Malayan plantation, a colonialist villa, an ultra-chic condominium in Miami and Tara from GWTW. ",
"cushion": " a numb, downcast, haggard Ishmail withdraws his hand. What, again, occurs is that this cushion, say - a thing normally as soft and downy as a baby's bottom - is, to his touch, now a hard, cold, compact block, as rock-hard as a diamond, as though part of a shadowy twin world consubstantial with Ishmail's own but caught through a glass darkly, a living mirror of our own world and just as cold, shiny and insular as a mirror. "
}
},
"bar": {
"name": "bar",
"message": "\nMAN, sitting down and barking (with gruff and, as you might say, military incivility): Barman! ",
"death": "BARMAN (abruptly dying): Aaaaaaah! Shhhhhhh . . . R.I.P. \nCOMMANDANT (about to go but first noticing his body): What a storm in a port-flip! \n\nWhich is what you might call adding insult to injury.",
"intro": "3\n \n\"Oh, how idiotic,\" murmurs Vowl. But just as idiotic, now, is his vision of a man going into a bar: ",
"items": {
"barman": "BARMAN (who knows a thing or two): Morning, mon Commandant. \nCOMMANDANT (calming down now that, although in mufti, his rank is plain to this barman): Ah, good morning to you, my boy, good morning! \nBARMAN (who has a slight but distinct hint of Oirishry about him): And what, pray, can I do for you, sir? Your wish is my command. \nCOMMANDANT (licking his lips): You know what I fancy most of all - a port-flip. \nBARMAN (frowning)-. What? ",
"port": "COMMANDANT (furiously pointing in front of him): Now look, that's port, isn't it? \nBARMAN (in agony): Uh huh . . . but. . . \nCOMMANDANT (livid): So? So? And (pointing again) that's an. . . "
}
}
}

@ -9,8 +9,9 @@
import random
import os
from time import sleep
import sys
import json
from time import sleep
global current_room
global visited_rooms
@ -19,6 +20,9 @@ current_room = "room"
visited_rooms=[]
viewedthings=[]
with open('voiddata.json', 'r') as f:
voiddata = json.load(f)
class bcolors:
BLUE = '\033[94m'
CYAN = '\033[96m'
@ -42,13 +46,13 @@ def delayPrint(s):
print("\n")
sys.stdout.write(">")
def interact(thing, roomthings):
def interact(thing):
print("")
delayPrint(roomthings[current_room][thing])
delayPrint(voiddata[current_room]["items"][thing])
viewedthings.append(thing)
def look(roomthings, current_room):
roomstring = ", a ".join(roomthings[current_room])
def look():
roomstring = ", a ".join(voiddata[current_room]["items"])
delayPrint(f"Looking around this spot, you sight a {roomstring}")
def portflip(rooms):
@ -65,10 +69,10 @@ def defaultReply():
messages = ["You cannot do that", "What?", "That won't work"]
return random.choice(messages)
def nextroom(death,rooms,intro,message):
def nextroom(rooms):
global current_room
sleep(1)
delayPrint(bcolors.RED + death[current_room] + bcolors.ENDC)
delayPrint(bcolors.RED + voiddata[current_room]["death"] + bcolors.ENDC)
sleep(1)
rooms.remove(current_room)
if len(rooms) == 0:
@ -76,10 +80,10 @@ def nextroom(death,rooms,intro,message):
current_room = random.choice(rooms)
print(bcolors.CYAN + "-"*79)
sleep(1)
delayPrint("\n" + " "*40 + intro[current_room])
delayPrint("\n" + " "*40 + voiddata[current_room]["intro"])
print("-"*79 + bcolors.ENDC)
sleep(1)
delayPrint(message[current_room])
delayPrint(voiddata[current_room]["message"])
def gameover():
print(bcolors.RED + "-"*79 + "\n" + "-"*80 + "\n" + "-"*80 + "\n")

@ -9,75 +9,16 @@
import random
import os
from time import sleep
import sys
import json
from time import sleep
import voidfunc
rooms = ["room", "island", "bar"]
visited_rooms=[]
viewedthings=[]
current_room = "room"
roomthings = {}
roomthings["room"]={"bookstand": "To his right is a mahogany stand on which sit 26 books - on which, I should say, 26 books normally ought to sit, but, as always, a book is missing, a book with an inscription, '5', on its flap. Nothing about this stand, though, looks at all abnormal or out of proportion, no hint of a missing publication, no filing card or 'ghost', as librarians quaintly call it, no conspicuous gap or blank",
"windowsill": "Crawling across his windowsill is a tiny animal, indigo and saffron in colour, not a cockroach, not a blowfly, but a kind of wasp, laboriously dragging a sugar crumb along with it. Hoping to crush it with a casual blow, Vowl lifts up his right hand; but it abruptly flaps its wings, flying off without giving its assailant an opportunity to do it any harm.",
"door": "Padding into his bathroom, Vowl dabs at his brow and throat with a damp cloth. Back to his room.",
"visiting-card": "Laid out languorously, all day long, on a couch or on a sofa, or on occasion rocking to and fro in his rocking chair, stubbornly trying to copy out on an old visiting-card that indistinct motif that had sprung at him from his rug, as frail as an infant but not now, thanks to Cochin's surgical skills, in all that much physical pain, our protagonist starts hallucinating, blowing his mind. ",
"rug": "His mind runs riot. Lost in thought, scrutinising his rug, Vowl starts imagining 5, 6, 26 distinct visual combinations, absorbing but also insubstantial, as though an artist's rough drafts but of what? - that, possibly, which a psychiatrist would call Jungian slips, an infinity of dark, mythic, anonymous portraits flitting through his brain, as it burrows for a solitary, global signal that might satisfy his natural human lust for signification both instant and lasting, a signal that might commandingly stand out from this chain of discontinuous links, this miasma of shadowy tracings, all of which, or so you would think, ought to knit up to form a kind of paradigmatic configuration, of which such partial motifs can furnish only anagrams and insipid approximations: \n a body crumpling up, a hoodlum, a portrait of an artist as a young dog; \n a bullock, a Bogartian falcon, a brooding blackbird; \n an arthritic old man; \n a sigh;"}
roomthings["island"]={
"stick": "At dusk, using a sharp rock, Ishmail cuts a notch on a stick (to tick off his first night as a castaway); and, with a total of 20 such cuts, constructs a hut, a sort of impromptu shack, with a door, four walls, and flooring and roofing built out of mud. With no matchsticks at hand, though, his food is invariably raw.",
"compound": "It was built, circa 1930, in a crypto-rococo fashion imitating, variously, a pink-icing casino in Monaco, a bungalow on a Malayan plantation, a colonialist villa, an ultra-chic condominium in Miami and Tara from GWTW. ",
"cushion": " a numb, downcast, haggard Ishmail withdraws his hand. What, again, occurs is that this cushion, say - a thing normally as soft and downy as a baby's bottom - is, to his touch, now a hard, cold, compact block, as rock-hard as a diamond, as though part of a shadowy twin world consubstantial with Ishmail's own but caught through a glass darkly, a living mirror of our own world and just as cold, shiny and insular as a mirror. "}
roomthings["bar"]={
"barman": """BARMAN (who knows a thing or two): Morning, mon Commandant.
COMMANDANT (calming down now that, although in mufti, his rank is plain to this barman): Ah, good morning to you, my boy, good morning!
BARMAN (who has a slight but distinct hint of Oirishry about him): And what, pray, can I do for you, sir? Your wish is my command.
COMMANDANT (licking his lips): You know what I fancy most of all - a port-flip.
BARMAN (frowning)-. What? """,
"port": """COMMANDANT (furiously pointing in front of him): Now look, that's port, isn't it?
BARMAN (in agony): Uh huh . . . but. . .
COMMANDANT (livid): So? So? And (pointing again) that's an. . . """}
bag = ["watch"]
message ={
"room": """
Incurably insomniac, Anton Vowl turns on a light. According to his watch it's only 12.20. With a loud and languorous sigh Vowl sits up, stuffs a pillow at his back, draws his quilt up around his chin, picks up his whodunit and idly scans a paragraph or two; but, judging its plot impossibly difficult to follow in his condition, its vocabulary too whimsically multisyllabic for comfort, throws it away in disgust.
""",
"island": """
But six days go past, and his unusually robust constitution allows him finally to sit up and look around him. Our protagonist is now disturbingly skinny but can still, if with difficulty, climb out of his pit a pit that was almost his tomb. So Ishmail starts living again.""",
"bar": """
MAN, sitting down and barking (with gruff and, as you might say, military incivility): Barman! """}
death ={
"room": """
It's all in vain. His subconscious vision starts buzzing around him again, buzzing around and within him, choking and suffocating him.""",
"island": """
At which point Ishmail falls victim to hallucinations, possibly from consuming a poisonous black mushroom or having had too much to drink; or, why not, from having shrunk so much as to vanish wholly from sight""",
"bar": """BARMAN (abruptly dying): Aaaaaaah! Shhhhhhh . . . R.I.P.
COMMANDANT (about to go but first noticing his body): What a storm in a port-flip!
Which is what you might call adding insult to injury.""",}
with open('voiddata.json', 'r') as f:
voiddata = json.load(f)
intro ={
"room":"""1
Which at first calls to mind a probably familiar story of a drunk man waking up with his brain in a whirl.""",
"island":"""2
In which luck, God's alias and alibi, plays a callous trick on a suitor cast away on an island.""",
rooms = ["room", "island", "bar"]
"bar": """3
"Oh, how idiotic," murmurs Vowl. But just as idiotic, now, is his vision of a man going into a bar: """}
class bcolors:
BLUE = '\033[94m'
CYAN = '\033[96m'
@ -89,66 +30,6 @@ class bcolors:
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
# Funtions
# ------------------
def delayPrint(s):
for c in s:
sys.stdout.write(c)
sys.stdout.flush()
sleep(0.01)
print("\n")
sys.stdout.write(">")
def interact(thing):
print("")
delayPrint(roomthings[current_room][thing])
viewedthings.append(thing)
def look():
roomstring = ", a ".join(roomthings[current_room])
delayPrint(f"Looking around this spot, you sight a {roomstring}")
def portflip():
global current_room
rooms.remove(current_room)
current_room = "bar"
rooms.append(current_room)
delayPrint("""COMMANDANT (vigorously nodding): That's right, a port-flip! Any port-flip in a storm, what? Ha ha ha!
BARMAN (as though in pain): I . . . don't .. . think . . . any . .. in .. . stock . . .
COMMANDANT (jumping up off his stool): What, no port-flips! But only last month I had (laboriously counting out) 1, 2, no, 3 port-flips in this bar!
BARMAN (almost inaudibly): But now . . . now . . . you can't. . . """)
def defaultReply():
messages = ["You cannot do that", "What?", "That won't work"]
return random.choice(messages)
def nextroom():
global current_room
sleep(1)
delayPrint(bcolors.RED + death[current_room] + bcolors.ENDC)
sleep(1)
rooms.remove(current_room)
if len(rooms) == 0:
gameover()
current_room = random.choice(rooms)
print(bcolors.CYAN + "-"*79)
sleep(1)
delayPrint("\n" + " "*40 + intro[current_room])
print("-"*79 + bcolors.ENDC)
sleep(1)
delayPrint(message[current_room])
def gameover():
print(bcolors.RED + "-"*79 + "\n" + "-"*80 + "\n" + "-"*80 + "\n")
sleep(1)
print("\n" + " "*28 + " / \ / \ / \ ")
print(" "*28 + "( f | i | n )")
print(" "*28 + " \_/ \_/ \_/ " + "\n")
sleep(1)
print("-"*79 + "\n" + "-"*80 + "\n" + "-"*80 + "\n" + bcolors.ENDC)
exit()
# Start of book
# ------------------
@ -194,10 +75,10 @@ print(bcolors.CYAN + "-"*80 +
""")
print("-"*80)
sleep(1)
delayPrint("\n" + " "*40 + intro[current_room])
voidfunc.delayPrint("\n" + " "*40 + voiddata[voidfunc.current_room]["intro"])
print("-"*79 + bcolors.ENDC)
sleep(1)
delayPrint(message[current_room])
voidfunc.delayPrint(voiddata[voidfunc.current_room]["message"])
while True:
# Wait for user input
@ -205,27 +86,27 @@ while True:
# End the game if all rooms have been explored
if len(rooms) == 0:
gameover()
voidfunc.gameover()
break
# End the room if all items have been interacted with
if any(s not in viewedthings for s in roomthings[current_room]):
if any(s not in voidfunc.viewedthings for s in voiddata[voidfunc.current_room]["items"]):
pass
else:
nextroom()
voidfunc.nextroom(rooms)
# Do functions based on reply
if "exit" in reply:
gameover()
voidfunc.gameover()
break
elif "e" in reply or len(roomthings[current_room]) == 0:
nextroom()
elif "e" in reply or len(voiddata[voidfunc.current_room]["items"]) == 0:
voidfunc.nextroom(rooms)
elif "port" in reply and "flip" in reply:
portflip()
elif any(word in reply.split() for word in roomthings[current_room]):
word = next((s for s in reply.split() if s in roomthings[current_room]), None)
interact(word)
elif any(s in reply for s in ["look", "scan", "watch", "study", "spot", "spy", "analysis", "probing", "grill", current_room]):
look()
voidfunc.portflip(rooms)
elif any(word in reply.split() for word in voiddata[voidfunc.current_room]["items"]):
word = next((s for s in reply.split() if s in voiddata[voidfunc.current_room]["items"]), None)
voidfunc.interact(word)
elif any(s in reply for s in ["look", "scan", "watch", "study", "spot", "spy", "analysis", "probing", "grill", voidfunc.current_room]):
voidfunc.look()
else:
delayPrint(defaultReply())
voidfunc.delayPrint(voidfunc.defaultReply())

@ -0,0 +1,7 @@
import json
with open('voiddata.json', 'r') as f:
voiddata = json.load(f)
# Output: {'name': 'Bob', 'languages': ['English', 'French']}
print(voiddata["bar"]["name"])

@ -0,0 +1,81 @@
import json
# Data to be written
roomthings = {}
roomthings["room"]={"bookstand": "To his right is a mahogany stand on which sit 26 books - on which, I should say, 26 books normally ought to sit, but, as always, a book is missing, a book with an inscription, '5', on its flap. Nothing about this stand, though, looks at all abnormal or out of proportion, no hint of a missing publication, no filing card or 'ghost', as librarians quaintly call it, no conspicuous gap or blank",
"windowsill": "Crawling across his windowsill is a tiny animal, indigo and saffron in colour, not a cockroach, not a blowfly, but a kind of wasp, laboriously dragging a sugar crumb along with it. Hoping to crush it with a casual blow, Vowl lifts up his right hand; but it abruptly flaps its wings, flying off without giving its assailant an opportunity to do it any harm.",
"door": "Padding into his bathroom, Vowl dabs at his brow and throat with a damp cloth. Back to his room.",
"visiting-card": "Laid out languorously, all day long, on a couch or on a sofa, or on occasion rocking to and fro in his rocking chair, stubbornly trying to copy out on an old visiting-card that indistinct motif that had sprung at him from his rug, as frail as an infant but not now, thanks to Cochin's surgical skills, in all that much physical pain, our protagonist starts hallucinating, blowing his mind. ",
"rug": "His mind runs riot. Lost in thought, scrutinising his rug, Vowl starts imagining 5, 6, 26 distinct visual combinations, absorbing but also insubstantial, as though an artist's rough drafts but of what? - that, possibly, which a psychiatrist would call Jungian slips, an infinity of dark, mythic, anonymous portraits flitting through his brain, as it burrows for a solitary, global signal that might satisfy his natural human lust for signification both instant and lasting, a signal that might commandingly stand out from this chain of discontinuous links, this miasma of shadowy tracings, all of which, or so you would think, ought to knit up to form a kind of paradigmatic configuration, of which such partial motifs can furnish only anagrams and insipid approximations: \n a body crumpling up, a hoodlum, a portrait of an artist as a young dog; \n a bullock, a Bogartian falcon, a brooding blackbird; \n an arthritic old man; \n a sigh;"}
roomthings["island"]={
"stick": "At dusk, using a sharp rock, Ishmail cuts a notch on a stick (to tick off his first night as a castaway); and, with a total of 20 such cuts, constructs a hut, a sort of impromptu shack, with a door, four walls, and flooring and roofing built out of mud. With no matchsticks at hand, though, his food is invariably raw.",
"compound": "It was built, circa 1930, in a crypto-rococo fashion imitating, variously, a pink-icing casino in Monaco, a bungalow on a Malayan plantation, a colonialist villa, an ultra-chic condominium in Miami and Tara from GWTW. ",
"cushion": " a numb, downcast, haggard Ishmail withdraws his hand. What, again, occurs is that this cushion, say - a thing normally as soft and downy as a baby's bottom - is, to his touch, now a hard, cold, compact block, as rock-hard as a diamond, as though part of a shadowy twin world consubstantial with Ishmail's own but caught through a glass darkly, a living mirror of our own world and just as cold, shiny and insular as a mirror. "}
roomthings["bar"]={
"barman": """BARMAN (who knows a thing or two): Morning, mon Commandant.
COMMANDANT (calming down now that, although in mufti, his rank is plain to this barman): Ah, good morning to you, my boy, good morning!
BARMAN (who has a slight but distinct hint of Oirishry about him): And what, pray, can I do for you, sir? Your wish is my command.
COMMANDANT (licking his lips): You know what I fancy most of all - a port-flip.
BARMAN (frowning)-. What? """,
"port": """COMMANDANT (furiously pointing in front of him): Now look, that's port, isn't it?
BARMAN (in agony): Uh huh . . . but. . .
COMMANDANT (livid): So? So? And (pointing again) that's an. . . """}
# -------------------
room = {
"name": "room",
"message": """
Incurably insomniac, Anton Vowl turns on a light. According to his watch it's only 12.20. With a loud and languorous sigh Vowl sits up, stuffs a pillow at his back, draws his quilt up around his chin, picks up his whodunit and idly scans a paragraph or two; but, judging its plot impossibly difficult to follow in his condition, its vocabulary too whimsically multisyllabic for comfort, throws it away in disgust.
""",
"death": """
It's all in vain. His subconscious vision starts buzzing around him again, buzzing around and within him, choking and suffocating him.""",
"intro":"""1
Which at first calls to mind a probably familiar story of a drunk man waking up with his brain in a whirl.""",
"items": roomthings["room"]
}
island = {
"name": "island",
"message": """
But six days go past, and his unusually robust constitution allows him finally to sit up and look around him. Our protagonist is now disturbingly skinny but can still, if with difficulty, climb out of his pit a pit that was almost his tomb. So Ishmail starts living again.""",
"death": """
At which point Ishmail falls victim to hallucinations, possibly from consuming a poisonous black mushroom or having had too much to drink; or, why not, from having shrunk so much as to vanish wholly from sight""",
"intro":"""2
In which luck, God's alias and alibi, plays a callous trick on a suitor cast away on an island.""",
"items": roomthings["island"]
}
bar = {
"name": "bar",
"message": """
MAN, sitting down and barking (with gruff and, as you might say, military incivility): Barman! """,
"death":"""BARMAN (abruptly dying): Aaaaaaah! Shhhhhhh . . . R.I.P.
COMMANDANT (about to go but first noticing his body): What a storm in a port-flip!
Which is what you might call adding insult to injury.""",
"intro": """3
"Oh, how idiotic," murmurs Vowl. But just as idiotic, now, is his vision of a man going into a bar: """,
"items": roomthings["bar"]
}
placedata = {"room":room, "island":island, "bar":bar}
# Serializing json
json_messages = json.dumps(placedata, indent=4)
# Writing to sample.json
with open("voiddata.json", "w") as outfile:
outfile.write(json_messages)

@ -0,0 +1,36 @@
{
"room": {
"name": "room",
"message": "\nIncurably insomniac, Anton Vowl turns on a light. According to his watch it's only 12.20. With a loud and languorous sigh Vowl sits up, stuffs a pillow at his back, draws his quilt up around his chin, picks up his whodunit and idly scans a paragraph or two; but, judging its plot impossibly difficult to follow in his condition, its vocabulary too whimsically multisyllabic for comfort, throws it away in disgust. \n",
"death": "\nIt's all in vain. His subconscious vision starts buzzing around him again, buzzing around and within him, choking and suffocating him.",
"intro": "1\n \nWhich at first calls to mind a probably familiar story of a drunk man waking up with his brain in a whirl.",
"items": {
"bookstand": "To his right is a mahogany stand on which sit 26 books - on which, I should say, 26 books normally ought to sit, but, as always, a book is missing, a book with an inscription, '5', on its flap. Nothing about this stand, though, looks at all abnormal or out of proportion, no hint of a missing publication, no filing card or 'ghost', as librarians quaintly call it, no conspicuous gap or blank",
"windowsill": "Crawling across his windowsill is a tiny animal, indigo and saffron in colour, not a cockroach, not a blowfly, but a kind of wasp, laboriously dragging a sugar crumb along with it. Hoping to crush it with a casual blow, Vowl lifts up his right hand; but it abruptly flaps its wings, flying off without giving its assailant an opportunity to do it any harm.",
"door": "Padding into his bathroom, Vowl dabs at his brow and throat with a damp cloth. Back to his room.",
"visiting-card": "Laid out languorously, all day long, on a couch or on a sofa, or on occasion rocking to and fro in his rocking chair, stubbornly trying to copy out on an old visiting-card that indistinct motif that had sprung at him from his rug, as frail as an infant but not now, thanks to Cochin's surgical skills, in all that much physical pain, our protagonist starts hallucinating, blowing his mind. ",
"rug": "His mind runs riot. Lost in thought, scrutinising his rug, Vowl starts imagining 5, 6, 26 distinct visual combinations, absorbing but also insubstantial, as though an artist's rough drafts but of what? - that, possibly, which a psychiatrist would call Jungian slips, an infinity of dark, mythic, anonymous portraits flitting through his brain, as it burrows for a solitary, global signal that might satisfy his natural human lust for signification both instant and lasting, a signal that might commandingly stand out from this chain of discontinuous links, this miasma of shadowy tracings, all of which, or so you would think, ought to knit up to form a kind of paradigmatic configuration, of which such partial motifs can furnish only anagrams and insipid approximations: \n a body crumpling up, a hoodlum, a portrait of an artist as a young dog; \n a bullock, a Bogartian falcon, a brooding blackbird; \n an arthritic old man; \n a sigh;"
}
},
"island": {
"name": "island",
"message": "\nBut six days go past, and his unusually robust constitution allows him finally to sit up and look around him. Our protagonist is now disturbingly skinny but can still, if with difficulty, climb out of his pit \u2014 a pit that was almost his tomb. So Ishmail starts living again.",
"death": "\nAt which point Ishmail falls victim to hallucinations, possibly from consuming a poisonous black mushroom or having had too much to drink; or, why not, from having shrunk so much as to vanish wholly from sight",
"intro": "2\n \nIn which luck, God's alias and alibi, plays a callous trick on a suitor cast away on an island.",
"items": {
"stick": "At dusk, using a sharp rock, Ishmail cuts a notch on a stick (to tick off his first night as a castaway); and, with a total of 20 such cuts, constructs a hut, a sort of impromptu shack, with a door, four walls, and flooring and roofing built out of mud. With no matchsticks at hand, though, his food is invariably raw.",
"compound": "It was built, circa 1930, in a crypto-rococo fashion imitating, variously, a pink-icing casino in Monaco, a bungalow on a Malayan plantation, a colonialist villa, an ultra-chic condominium in Miami and Tara from GWTW. ",
"cushion": " a numb, downcast, haggard Ishmail withdraws his hand. What, again, occurs is that this cushion, say - a thing normally as soft and downy as a baby's bottom - is, to his touch, now a hard, cold, compact block, as rock-hard as a diamond, as though part of a shadowy twin world consubstantial with Ishmail's own but caught through a glass darkly, a living mirror of our own world and just as cold, shiny and insular as a mirror. "
}
},
"bar": {
"name": "bar",
"message": "\nMAN, sitting down and barking (with gruff and, as you might say, military incivility): Barman! ",
"death": "BARMAN (abruptly dying): Aaaaaaah! Shhhhhhh . . . R.I.P. \nCOMMANDANT (about to go but first noticing his body): What a storm in a port-flip! \n\nWhich is what you might call adding insult to injury.",
"intro": "3\n \n\"Oh, how idiotic,\" murmurs Vowl. But just as idiotic, now, is his vision of a man going into a bar: ",
"items": {
"barman": "BARMAN (who knows a thing or two): Morning, mon Commandant. \nCOMMANDANT (calming down now that, although in mufti, his rank is plain to this barman): Ah, good morning to you, my boy, good morning! \nBARMAN (who has a slight but distinct hint of Oirishry about him): And what, pray, can I do for you, sir? Your wish is my command. \nCOMMANDANT (licking his lips): You know what I fancy most of all - a port-flip. \nBARMAN (frowning)-. What? ",
"port": "COMMANDANT (furiously pointing in front of him): Now look, that's port, isn't it? \nBARMAN (in agony): Uh huh . . . but. . . \nCOMMANDANT (livid): So? So? And (pointing again) that's an. . . "
}
}
}

@ -0,0 +1,36 @@
{
"room": {
"name": "room",
"message": "\nIncurably insomniac, Anton Vowl turns on a light. According to his watch it's only 12.20. With a loud and languorous sigh Vowl sits up, stuffs a pillow at his back, draws his quilt up around his chin, picks up his whodunit and idly scans a paragraph or two; but, judging its plot impossibly difficult to follow in his condition, its vocabulary too whimsically multisyllabic for comfort, throws it away in disgust. \n",
"death": "\nIt's all in vain. His subconscious vision starts buzzing around him again, buzzing around and within him, choking and suffocating him.",
"intro": "1\n \nWhich at first calls to mind a probably familiar story of a drunk man waking up with his brain in a whirl.",
"items": {
"bookstand": "To his right is a mahogany stand on which sit 26 books - on which, I should say, 26 books normally ought to sit, but, as always, a book is missing, a book with an inscription, '5', on its flap. Nothing about this stand, though, looks at all abnormal or out of proportion, no hint of a missing publication, no filing card or 'ghost', as librarians quaintly call it, no conspicuous gap or blank",
"windowsill": "Crawling across his windowsill is a tiny animal, indigo and saffron in colour, not a cockroach, not a blowfly, but a kind of wasp, laboriously dragging a sugar crumb along with it. Hoping to crush it with a casual blow, Vowl lifts up his right hand; but it abruptly flaps its wings, flying off without giving its assailant an opportunity to do it any harm.",
"door": "Padding into his bathroom, Vowl dabs at his brow and throat with a damp cloth. Back to his room.",
"visiting-card": "Laid out languorously, all day long, on a couch or on a sofa, or on occasion rocking to and fro in his rocking chair, stubbornly trying to copy out on an old visiting-card that indistinct motif that had sprung at him from his rug, as frail as an infant but not now, thanks to Cochin's surgical skills, in all that much physical pain, our protagonist starts hallucinating, blowing his mind. ",
"rug": "His mind runs riot. Lost in thought, scrutinising his rug, Vowl starts imagining 5, 6, 26 distinct visual combinations, absorbing but also insubstantial, as though an artist's rough drafts but of what? - that, possibly, which a psychiatrist would call Jungian slips, an infinity of dark, mythic, anonymous portraits flitting through his brain, as it burrows for a solitary, global signal that might satisfy his natural human lust for signification both instant and lasting, a signal that might commandingly stand out from this chain of discontinuous links, this miasma of shadowy tracings, all of which, or so you would think, ought to knit up to form a kind of paradigmatic configuration, of which such partial motifs can furnish only anagrams and insipid approximations: \n a body crumpling up, a hoodlum, a portrait of an artist as a young dog; \n a bullock, a Bogartian falcon, a brooding blackbird; \n an arthritic old man; \n a sigh;"
}
},
"island": {
"name": "island",
"message": "\nBut six days go past, and his unusually robust constitution allows him finally to sit up and look around him. Our protagonist is now disturbingly skinny but can still, if with difficulty, climb out of his pit \u2014 a pit that was almost his tomb. So Ishmail starts living again.",
"death": "\nAt which point Ishmail falls victim to hallucinations, possibly from consuming a poisonous black mushroom or having had too much to drink; or, why not, from having shrunk so much as to vanish wholly from sight",
"intro": "2\n \nIn which luck, God's alias and alibi, plays a callous trick on a suitor cast away on an island.",
"items": {
"stick": "At dusk, using a sharp rock, Ishmail cuts a notch on a stick (to tick off his first night as a castaway); and, with a total of 20 such cuts, constructs a hut, a sort of impromptu shack, with a door, four walls, and flooring and roofing built out of mud. With no matchsticks at hand, though, his food is invariably raw.",
"compound": "It was built, circa 1930, in a crypto-rococo fashion imitating, variously, a pink-icing casino in Monaco, a bungalow on a Malayan plantation, a colonialist villa, an ultra-chic condominium in Miami and Tara from GWTW. ",
"cushion": " a numb, downcast, haggard Ishmail withdraws his hand. What, again, occurs is that this cushion, say - a thing normally as soft and downy as a baby's bottom - is, to his touch, now a hard, cold, compact block, as rock-hard as a diamond, as though part of a shadowy twin world consubstantial with Ishmail's own but caught through a glass darkly, a living mirror of our own world and just as cold, shiny and insular as a mirror. "
}
},
"bar": {
"name": "bar",
"message": "\nMAN, sitting down and barking (with gruff and, as you might say, military incivility): Barman! ",
"death": "BARMAN (abruptly dying): Aaaaaaah! Shhhhhhh . . . R.I.P. \nCOMMANDANT (about to go but first noticing his body): What a storm in a port-flip! \n\nWhich is what you might call adding insult to injury.",
"intro": "3\n \n\"Oh, how idiotic,\" murmurs Vowl. But just as idiotic, now, is his vision of a man going into a bar: ",
"items": {
"barman": "BARMAN (who knows a thing or two): Morning, mon Commandant. \nCOMMANDANT (calming down now that, although in mufti, his rank is plain to this barman): Ah, good morning to you, my boy, good morning! \nBARMAN (who has a slight but distinct hint of Oirishry about him): And what, pray, can I do for you, sir? Your wish is my command. \nCOMMANDANT (licking his lips): You know what I fancy most of all - a port-flip. \nBARMAN (frowning)-. What? ",
"port": "COMMANDANT (furiously pointing in front of him): Now look, that's port, isn't it? \nBARMAN (in agony): Uh huh . . . but. . . \nCOMMANDANT (livid): So? So? And (pointing again) that's an. . . "
}
}
}

@ -9,8 +9,9 @@
import random
import os
from time import sleep
import sys
import json
from time import sleep
global current_room
global visited_rooms
@ -19,6 +20,9 @@ current_room = "room"
visited_rooms=[]
viewedthings=[]
with open('voiddata.json', 'r') as f:
voiddata = json.load(f)
class bcolors:
BLUE = '\033[94m'
CYAN = '\033[96m'
@ -42,13 +46,13 @@ def delayPrint(s):
print("\n")
sys.stdout.write(">")
def interact(thing, roomthings):
def interact(thing):
print("")
delayPrint(roomthings[current_room][thing])
delayPrint(voiddata[current_room]["items"][thing])
viewedthings.append(thing)
def look(roomthings, current_room):
roomstring = ", a ".join(roomthings[current_room])
def look():
roomstring = ", a ".join(voiddata[current_room]["items"])
delayPrint(f"Looking around this spot, you sight a {roomstring}")
def portflip(rooms):
@ -65,10 +69,10 @@ def defaultReply():
messages = ["You cannot do that", "What?", "That won't work"]
return random.choice(messages)
def nextroom(death,rooms,intro,message):
def nextroom(rooms):
global current_room
sleep(1)
delayPrint(bcolors.RED + death[current_room] + bcolors.ENDC)
delayPrint(bcolors.RED + voiddata[current_room]["death"] + bcolors.ENDC)
sleep(1)
rooms.remove(current_room)
if len(rooms) == 0:
@ -76,10 +80,10 @@ def nextroom(death,rooms,intro,message):
current_room = random.choice(rooms)
print(bcolors.CYAN + "-"*79)
sleep(1)
delayPrint("\n" + " "*40 + intro[current_room])
delayPrint("\n" + " "*40 + voiddata[current_room]["intro"])
print("-"*79 + bcolors.ENDC)
sleep(1)
delayPrint(message[current_room])
delayPrint(voiddata[current_room]["message"])
def gameover():
print(bcolors.RED + "-"*79 + "\n" + "-"*80 + "\n" + "-"*80 + "\n")

Loading…
Cancel
Save