Refactor lab with fancy printing

This commit is contained in:
Chris Proctor
2023-07-12 13:48:50 -04:00
parent 56b70e9b7e
commit 4825451351
10 changed files with 211 additions and 124 deletions

View File

@@ -1,17 +1,25 @@
# ghost.py
# --------
# By MWC Contributors
#
# This is a Python program. You can run it by typing `python ghost.py`
# This is a Python file. You can run it by typing "python ghost.py"
import sys
from pathlib import Path
sys.path.append('../../../..')
from fancy_printing import print_fancy
GHOST_GIVES_KEY = [
"You enter the cramped galley and notice a sad, lonely ghost wandering around. You always wondered if you would be afraid of ghosts, but somehow this feels completely normal. The ghost begins to speak.",
"'It has been a long while since I have seen anybody down here,' she says. 'I would like to give you a gift. Here's a key.'"
]
GHOST_IS_BORED = [
"The ghost glances over at you. 'I hope you find some use for that key.'"
]
KEY = " Even in the faint light of your lamp, the key has a golden gleam.\n\n"
if Path("key.txt").exists():
print(" The ghost glances over at you. 'I hope you find some use for that key.'")
print_fancy(GHOST_IS_BORED)
else:
print(" You enter the cramped galley and notice a sad, lonely ghost wandering")
print(" around. You always wondered if you would be afraid of ghosts, but")
print(" somehow this feels completely normal. The ghost begins to speak.")
print("")
print(" 'It has been a long while since I have seen anybody down here,' she says")
print(" 'I would like to give you a gift. Here's a key.'")
with open("key.txt", "w") as keyfile:
keyfile.write(" Even in the faint light of your lamp, the key has a golden gleam.\n")
print_fancy(GHOST_GIVES_KEY)
Path("key.txt").write_text(KEY)

View File

@@ -1,14 +1,26 @@
# This is a Python program. You can run it by typing "python desk.py"
# desk.py
# --------
# By MWC Contributors
#
# This is a Python program. You can run it by typing `python desk.py`
import sys
from pathlib import Path
sys.path.append('../../../..')
from fancy_printing import print_fancy
print(" The stateroom contains the ruins of an elegant office. Scraps of wallpaper")
print(" are peeling from the wall; there is an eel living in the chandelier.")
print(" There is a huge desk at the center of the room.")
DESCRIPTION = [
"The stateroom contains the ruins of an elegant office. Scraps of wallpaper are peeling from the wall; there is an eel living in the chandelier. There is a huge desk at the center of the room."
]
OPEN_DESK = [
"You try your key in the desk drawer, and it clicks open. There are many decaying pieces of paper. One has the numbers 318 written in a fine script."
]
DESK_LOCKED = [
"You try to open the desk's drawer, but it is firmly locked."
]
print_fancy(DESCRIPTION)
if Path("../galley/key.txt").exists():
print(" You try your key in the desk drawer, and it clicks open. There are")
print(" many decaying pieces of paper. One has the numbers 318 written in")
print(" a fine script.")
print_fancy(OPEN_DESK)
else:
print(" You try to open the desk's drawer, but it is firmly locked.")
print_fancy(DESK_LOCKED)