From f7c50fc8609a317b34dc5c51ef8c4e6b4da2990d Mon Sep 17 00:00:00 2001 From: log Date: Tue, 24 Jan 2023 18:09:35 +0100 Subject: [PATCH] moved data to JSON --- avoid/.ipynb_checkpoints/a-void-checkpoint.py | 112 ++++++++++++ .../.ipynb_checkpoints/jsonread-checkpoint.py | 7 + .../.ipynb_checkpoints/jsontest-checkpoint.py | 81 +++++++++ .../.ipynb_checkpoints/sample-checkpoint.json | 6 + .../voiddata-checkpoint.json | 36 ++++ .../.ipynb_checkpoints/voidfunc-checkpoint.py | 22 ++- avoid/__pycache__/voidfunc.cpython-39.pyc | Bin 0 -> 3363 bytes avoid/a-void.py | 161 +++--------------- avoid/jsonread.py | 7 + avoid/jsontest.py | 81 +++++++++ avoid/sample.json | 36 ++++ avoid/voiddata.json | 36 ++++ avoid/voidfunc.py | 22 ++- 13 files changed, 449 insertions(+), 158 deletions(-) create mode 100644 avoid/.ipynb_checkpoints/a-void-checkpoint.py create mode 100644 avoid/.ipynb_checkpoints/jsonread-checkpoint.py create mode 100644 avoid/.ipynb_checkpoints/jsontest-checkpoint.py create mode 100644 avoid/.ipynb_checkpoints/sample-checkpoint.json create mode 100644 avoid/.ipynb_checkpoints/voiddata-checkpoint.json create mode 100644 avoid/__pycache__/voidfunc.cpython-39.pyc create mode 100644 avoid/jsonread.py create mode 100644 avoid/jsontest.py create mode 100644 avoid/sample.json create mode 100644 avoid/voiddata.json diff --git a/avoid/.ipynb_checkpoints/a-void-checkpoint.py b/avoid/.ipynb_checkpoints/a-void-checkpoint.py new file mode 100644 index 0000000..5b3ecfe --- /dev/null +++ b/avoid/.ipynb_checkpoints/a-void-checkpoint.py @@ -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()) \ No newline at end of file diff --git a/avoid/.ipynb_checkpoints/jsonread-checkpoint.py b/avoid/.ipynb_checkpoints/jsonread-checkpoint.py new file mode 100644 index 0000000..09ff16a --- /dev/null +++ b/avoid/.ipynb_checkpoints/jsonread-checkpoint.py @@ -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"]) \ No newline at end of file diff --git a/avoid/.ipynb_checkpoints/jsontest-checkpoint.py b/avoid/.ipynb_checkpoints/jsontest-checkpoint.py new file mode 100644 index 0000000..83f34da --- /dev/null +++ b/avoid/.ipynb_checkpoints/jsontest-checkpoint.py @@ -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) \ No newline at end of file diff --git a/avoid/.ipynb_checkpoints/sample-checkpoint.json b/avoid/.ipynb_checkpoints/sample-checkpoint.json new file mode 100644 index 0000000..64af536 --- /dev/null +++ b/avoid/.ipynb_checkpoints/sample-checkpoint.json @@ -0,0 +1,6 @@ +{ + "name": "sathiyajith", + "rollno": 56, + "cgpa": 8.6, + "phonenumber": "9976770500" +} \ No newline at end of file diff --git a/avoid/.ipynb_checkpoints/voiddata-checkpoint.json b/avoid/.ipynb_checkpoints/voiddata-checkpoint.json new file mode 100644 index 0000000..1a3ca11 --- /dev/null +++ b/avoid/.ipynb_checkpoints/voiddata-checkpoint.json @@ -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. . . " + } + } +} \ No newline at end of file diff --git a/avoid/.ipynb_checkpoints/voidfunc-checkpoint.py b/avoid/.ipynb_checkpoints/voidfunc-checkpoint.py index 475a920..5d4d803 100644 --- a/avoid/.ipynb_checkpoints/voidfunc-checkpoint.py +++ b/avoid/.ipynb_checkpoints/voidfunc-checkpoint.py @@ -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") diff --git a/avoid/__pycache__/voidfunc.cpython-39.pyc b/avoid/__pycache__/voidfunc.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..75b97f644640b4fcc37007067d54537e99ccf8a3 GIT binary patch literal 3363 zcmb^zO>Y~=b!I=v)r$Ivti*8Aq9eCRL{}en>;$M$#Fiz(4j|Kk;=uJL1u^2R$d#8n z%*;@VSmh+&do55Dka{SPOOO2>JQxWAG-br06_%JNm62(P&fAy&tX6D0egAS3zLu%;qyv|@GA5u zoe+TtkGwy=o5ZPqJekHPG^srUY5@tzkxxl6dyDApn}oXGbAS(tsEF!IBC1DTG9@B0 z@scFdA{LW?XGBd*0iG4pVg~SAVphBbcuvfTD}b+vdGR*jc|kuX^>=;%-bu4gZK(4! z?b|>}*&9yn$xH}t_{y%9g{7*E$Idnill##1O#mrDfk9Xbf_h0H{3H}XQW0TN6_q3s z)nr0MNh~IkNfE=fleW6umbp}V7{2%AZ|?LQ`nW_NmgshgZaH-Oquwxh@5`GG!V-+{ z^qTdWjasdO_tI9&#;sOQib0O!TC4T-fajx~;KAk>4I8XKUu)X%;Z~#3w3X+L&CMsz ztiRRRu+_(F4;#&=Yc^;!H`ZP|7_=O1sJ%W|50}~1lN98%;<2gY<@j-GG4sZ+F~M;~D=Nyp(Go={4fkg5&Uzyyo9; zT3`q`?CE+%p)wtP8;u>-*4hK5z$7hnWLw+I(*0DJZdPG?5d@-)%pb!jL(oFZISz-rrz;xE>8aP}JY_Kb{LNWMAEg(RZf)Fu^s12yT zb5W8Y2ihOQF^yajI!D#}fd980P=-T-GB{mRPGRPiGmzv|2C#s?%@zL>s9^ocxj16D{OfT#Lh_O#2*2bw7q1qJU*WtMmHtiQn4ii6WB%L>@lMylQt z+lPy;Zz8EcYxCPc$ z@C&yIceKZw@mc+a(>&e1& zftfBBY%%BCQe~ws+F)9Pbm4K;*{vn^AyQgmx6cqm=A7|CuV=;0dlE=z1s{lPJ3jzU z@X|u=kAyoNp}({_XrNRExJ*T*J-L^b{_;yOu5+62AkI6dx#%wuS_Tbs7mjMoY{ZKp zKE+i18pds07`Jop7eiSGy#KH0@#Gl1<^=PK*R1=)x#uNYg)~e^5Rsco{xM4EEbRXBe2WchO2 zupYDjvq8`;jFPrGvPpf~B?sqKE^(>@ngd58UT=>Qs zOVts)PO@cUi3-TC=&X-mQ{!3UMf7J7kYh+L6@b$&I3rXa!R|RH#p6D7XZCFv7zk~< zP@!Cf^a9;Kk6o(qMNlS9D9Bv$6qOOKUf7R-*4W%3I)gLWL{nikq~-w(Kf7F0EibE8 zBzxn{7F%Usv2h>P-(=fGw!;ot2EAbQ;f*&PWnZ;`=BUTR|6Ht+zI=k?S_3P% z($TRpQt0D0NWaO<8RvCwjHQvf1K@Yi^(+8FuY;qGf78_M*57u|!Fp1wci;?UdaSnt zll9W_eJ#LhGPRd!sCk5|X|%fTPD&_cEZwn?>bWQ%o?{P-16Q!PjPJs?i;C`zxLbdU lSsVSfte!u?2dVLjF|W1IRjOW%E_%~5Q51zy5XI1E{|m=W!bboA literal 0 HcmV?d00001 diff --git a/avoid/a-void.py b/avoid/a-void.py index 24353e0..5b3ecfe 100644 --- a/avoid/a-void.py +++ b/avoid/a-void.py @@ -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()) \ No newline at end of file + voidfunc.delayPrint(voidfunc.defaultReply()) \ No newline at end of file diff --git a/avoid/jsonread.py b/avoid/jsonread.py new file mode 100644 index 0000000..09ff16a --- /dev/null +++ b/avoid/jsonread.py @@ -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"]) \ No newline at end of file diff --git a/avoid/jsontest.py b/avoid/jsontest.py new file mode 100644 index 0000000..83f34da --- /dev/null +++ b/avoid/jsontest.py @@ -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) \ No newline at end of file diff --git a/avoid/sample.json b/avoid/sample.json new file mode 100644 index 0000000..1a3ca11 --- /dev/null +++ b/avoid/sample.json @@ -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. . . " + } + } +} \ No newline at end of file diff --git a/avoid/voiddata.json b/avoid/voiddata.json new file mode 100644 index 0000000..1a3ca11 --- /dev/null +++ b/avoid/voiddata.json @@ -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. . . " + } + } +} \ No newline at end of file diff --git a/avoid/voidfunc.py b/avoid/voidfunc.py index 475a920..5d4d803 100644 --- a/avoid/voidfunc.py +++ b/avoid/voidfunc.py @@ -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")