Refactor lab with fancy printing
This commit is contained in:
@@ -1,48 +1,53 @@
|
||||
# This is a Python program. You should run it by typing "chest.py"
|
||||
# chest.py
|
||||
# --------
|
||||
# By MWC Contributors
|
||||
#
|
||||
# This is a Python program. You should run it by typing `python chest.py`.
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
from urllib.request import urlretrieve
|
||||
import threading
|
||||
import datetime
|
||||
from threading import Timer
|
||||
from datetime import datetime
|
||||
import sys
|
||||
sys.path.append('../../..')
|
||||
from fancy_printing import print_fancy
|
||||
|
||||
def treasure():
|
||||
print(" something shining brightly from within, so bright you can't")
|
||||
print(" quite make out what it is.\n")
|
||||
|
||||
def monster1():
|
||||
print(" *rumble* *rumble* *rumble* \n")
|
||||
print(" Around the reef, nothing seems out of place.\n")
|
||||
|
||||
def monster2():
|
||||
print(" *rumble* *rumble* *rumble* \n")
|
||||
print(" A SEA MONSTER APPEARS FROM THE REEF! \n")
|
||||
print(" The sea monster must have seen you open the chest!")
|
||||
print(" There's no time to squander. You grab the treasure from the chest without taking a closer look!")
|
||||
print(" Quick, use mkdir to make a \"bag\" directory and mv to")
|
||||
print(" hide the treasure.jpg in the bag. ")
|
||||
print(" Then get back to the surface ASAP! The monster is coming! \n")
|
||||
print(" Don't forget to take your treasure bag with you up to the top directory!")
|
||||
now = datetime.datetime.now()
|
||||
with open(".timer", "w") as timerfile:
|
||||
timerfile.write(str(now))
|
||||
|
||||
|
||||
secret = "318"
|
||||
|
||||
print(" You approach the chest and see that the lock is surprisingly free of rust.")
|
||||
print(" In fact, the code dials turn smoothly. Try entering a code.")
|
||||
CHEST_TIMER_FILE = ".timer"
|
||||
SECRET = "318"
|
||||
APPROACH_CHEST = [
|
||||
"You approach the chest and see that the lock is surprisingly free of rust. In fact, the code dials turn smoothly. Try entering a code."
|
||||
]
|
||||
CHEST_OPENS = [
|
||||
"The chest snaps open, releasing several huge air bubbles. You look into the chest and see..."
|
||||
]
|
||||
TREASURE = [
|
||||
"something shining brightly from within, so bright you can't quite make out what it is."
|
||||
]
|
||||
MONSTER1 = [
|
||||
"*rumble* *rumble* *rumble*",
|
||||
"Around the reef, nothing seems out of place."
|
||||
]
|
||||
MONSTER2 = [
|
||||
"*rumble* *rumble* *rumble*",
|
||||
"A SEA MONSTER APPEARS FROM THE REEF!",
|
||||
"The sea monster must have seen you open the chest! There's no time to squander. You grab the treasure from the chest without taking a closer look! Quick, make a bag and store your treasure inside, using the following comamnds:",
|
||||
"mkdir bag",
|
||||
"mv treasure.jpg bag",
|
||||
"Then get back to the surface ASAP! Don't forget to take your treasure bag with you. Remember, `..` means 'the parent directory,' so these commands will move the bag to the parent directory and then move yourself:",
|
||||
"mv bag ../bag",
|
||||
"cd .."
|
||||
]
|
||||
|
||||
print_fancy(APPROACH_CHEST)
|
||||
guess = input(" > ")
|
||||
|
||||
if guess == secret:
|
||||
print(" The chest snaps open, releasing several huge air bubbles.")
|
||||
print(" You look into the chest and see...\n")
|
||||
if guess.strip() == SECRET:
|
||||
Path(CHEST_TIMER_FILE).write_text(datetime.now().isoformat())
|
||||
print_fancy(CHEST_OPENS)
|
||||
os.system('cp ./../../../.assets/fork.jpg treasure.jpg')
|
||||
timer1 = threading.Timer(1.0, treasure)
|
||||
timer2 = threading.Timer(3.0, monster1)
|
||||
timer3 = threading.Timer(5.0, monster2)
|
||||
timer1.start()
|
||||
timer2.start()
|
||||
timer3.start()
|
||||
Timer(1.0, print_fancy, [TREASURE]).start()
|
||||
Timer(3.0, print_fancy, [MONSTER1]).start()
|
||||
Timer(5.0, print_fancy, [MONSTER2]).start()
|
||||
else:
|
||||
print(" nothing happens. Maybe next time.")
|
||||
print_fancy(["nothing happens. Maybe next time."])
|
||||
|
@@ -3,5 +3,5 @@
|
||||
to be at the edge of a plateau whose edges are encrusted with beautiful
|
||||
corals.
|
||||
|
||||
Both sunken_ship and coral_reef are directories, so use the "cd" command
|
||||
Both sunken_ship and coral_reef are directories, so use the `cd` command
|
||||
to go into whichever one you want.
|
||||
|
@@ -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)
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user