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."])
|
||||
|
Reference in New Issue
Block a user