generated from mwc/lab_terminal
63 lines
2.6 KiB
Python
63 lines
2.6 KiB
Python
# return_to_ship.py
|
|
# -----------------
|
|
# By MWC Contributors
|
|
#
|
|
# This is a Python program. You should run it by typing `python return_to_ship.py`.
|
|
|
|
from shutil import rmtree
|
|
from pathlib import Path
|
|
from datetime import datetime
|
|
from datetime import timedelta
|
|
from fancy_printing import print_fancy
|
|
|
|
CHEST_TIMER_FILE = "adventure/seafloor/coral_reef/.timer"
|
|
BEGINNING = [
|
|
"Your adventure has only just begun. You are not yet ready to return to the ship. More secrets await you in the ocean's depths. Use `ls` to look around, and use `cd adventure` to start the adventure..."
|
|
]
|
|
FORGOT_BAG = [
|
|
"You forgot your treasure bag! Hurry back to get it before the sea monster hides it away forever!"
|
|
]
|
|
LOST_TREASURE = [
|
|
"You are swimming as fast as you can towards the boat but you can feel the water begin to pull you back as the sea monster opens its giant mouth. You kick with all your might, sure that you are about to breath your last breath.",
|
|
"Suddenly... The treasure bag slips out of your hand!",
|
|
"It swirls down through the water and into the mouth of the sea monster. The beast's mouth snaps closed and it jets away into the depth of the ocean, taking with it the treasure. You are safe... but will you attempt the dive again?"
|
|
]
|
|
VICTORY = [
|
|
"You are swimming as fast as you can towards the boat but you can feel the water begin to pull you back as the sea monster opens its giant mouth. You kick with all your might, sure that you are about to breathe your last breath."
|
|
"Suddenly... A hand appears! You've made it to the boat! The crew pulls you into the boat, just in time to avoid the sea monster's vicious maw. You're safe at last! Now you can finally show off the treasure you risked your life for... Use `open bag/treasure.jpg` to take a peek.",
|
|
"Congratulations! You have completed the Terminal Adventure."
|
|
]
|
|
|
|
def reset():
|
|
rmtree('bag')
|
|
Path('adventure/seafloor/coral_reef/.timer').unlink()
|
|
print_fancy(LOST_TREASURE)
|
|
|
|
def win():
|
|
print_fancy(VICTORY)
|
|
|
|
def chest_was_opened():
|
|
return Path(CHEST_TIMER_FILE).exists()
|
|
|
|
def treasure_is_present():
|
|
return Path("bag/treasure.jpg").exists()
|
|
|
|
def time_since_chest_was_opened():
|
|
if chest_was_opened():
|
|
treasure_opened_time = datetime.fromisoformat(Path(CHEST_TIMER_FILE).read_text())
|
|
elapsed_time = datetime.now() - treasure_opened_time
|
|
return elapsed_time.seconds
|
|
else:
|
|
return 0
|
|
|
|
if chest_was_opened():
|
|
if treasure_is_present():
|
|
if time_since_chest_was_opened() < 60:
|
|
win()
|
|
else:
|
|
reset()
|
|
else:
|
|
print_fancy(FORGOT_BAG)
|
|
else:
|
|
print_fancy(BEGINNING)
|