Initial commit

This commit is contained in:
cchung 2023-07-13 00:27:16 +00:00
commit fad932f52a
14 changed files with 299 additions and 0 deletions

BIN
.assets/fork.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

10
.commit_template Normal file
View File

@ -0,0 +1,10 @@
# -----------------------------------------------------------------
# Write a few sentences above this line answering the following
# questions:
#
# How was your experience moving around the Terminal? Can you imagine
# tasks for which using the Terminal might be easier than using the
# the desktop and mouse?

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
bag
treasure.png
key.txt
.timer
**/__pycache__/

View File

@ -0,0 +1,53 @@
# 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
from threading import Timer
from datetime import datetime
import sys
sys.path.append('../../..')
from fancy_printing import print_fancy
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 commands:",
"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.strip() == SECRET:
Path(CHEST_TIMER_FILE).write_text(datetime.now().isoformat())
print_fancy(CHEST_OPENS)
os.system('cp ./../../../.assets/fork.jpg treasure.jpg')
Timer(1.0, print_fancy, [TREASURE]).start()
Timer(3.0, print_fancy, [MONSTER1]).start()
Timer(5.0, print_fancy, [MONSTER2]).start()
else:
print_fancy(["nothing happens. Maybe next time."])

View File

@ -0,0 +1,23 @@
You are standing at the edge of a beautiful coral reef. Schools of fish are
swirling around you in every direction. In front of you is a deep chasm
where you see larger fish sliding through the shadows. There is a chest
half-buried in the seafloor.
____...------------...____
_.-"` /o/__ ____ __ __ __ \o\_`"-._
.' / / \ \ '.
|=====/o/======================\o\=====|
|____/_/________..____..________\_\____|
/ _/ \_ <_o#\__/#o_> _/ \_ \
\________________\####/________________/
|===\!/========================\!/===|
| |=| .---. |=| |
|===|o|=========/ \========|o|===|
| | | \() ()/ | | |
|===|o|======{'-.) A (.-'}=====|o|===|
| __/ \__ '-.\uuu/.-' __/ \__ |
|============= .'.'^'.'.=============|
| _\o/ __ {.' __ '.} _ _\o/ _|

View File

@ -0,0 +1,7 @@
After several moments of peaceful floating, you make a gentle landing on
the seafloor, several hundered meters away from the sunken ship. You appear
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
to go into whichever one you want.

View File

@ -0,0 +1,25 @@
# ghost.py
# --------
# By MWC Contributors
#
# This is a Python program. 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_fancy(GHOST_IS_BORED)
else:
print_fancy(GHOST_GIVES_KEY)
Path("key.txt").write_text(KEY)

View File

@ -0,0 +1,6 @@
The sunken ship is lying on the seafloor at a slight angle. From the remains
of its masts and rigging, you can tell it's from the age before ships were made
of steel and powered by engines. You climb up in the deck, and see a large hole
allowing access to the inner chambers. You flick on your suit's light and
go inside.

View File

@ -0,0 +1,26 @@
# 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
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_fancy(OPEN_DESK)
else:
print_fancy(DESK_LOCKED)

9
adventure/sinking.txt Normal file
View File

@ -0,0 +1,9 @@
As you are lowered off the edge of the research boat, you wave goodbye to
your friends. The diving suit is tight and stiff, and your vision is limited
to the round window in front of you. Your head goes below water, and the
sharp details of the boat are replaced by a wash of blues and greens. Below
you is an endless expanse of water. You can just barely see the sunken ship
on the seafloor. You relax, allowing your body to gently float down...
To continue, you need to go into the seafloor directory by typing
"cd seafloor". Once you're there, type `ls` to see what's inside.

25
fancy_printing.py Normal file
View File

@ -0,0 +1,25 @@
# fancy_printing.py
# -----------------
# By MWC Contributors
#
# This module defines the `fancy_printing` function,
# which nicely formats and prints a list of strings.
# All the other python programs in this lab import
# `fancy_printing`.
from click import secho
from textwrap import wrap
def print_fancy(paragraphs):
"""Formats and prints paragraphs.
`paragraphs` should be a list of strings.
"""
for paragraph in paragraphs:
wrapped_text = wrap(paragraph, initial_indent=' ', subsequent_indent=' ')
for line in wrapped_text:
secho(line, fg='cyan')
print('')
if __name__ == '__main__':
print_fancy(["This is a just a helper program :)"])

31
poetry.lock generated Normal file
View File

@ -0,0 +1,31 @@
# This file is automatically @generated by Poetry 1.5.1 and should not be changed by hand.
[[package]]
name = "click"
version = "8.1.4"
description = "Composable command line interface toolkit"
optional = false
python-versions = ">=3.7"
files = [
{file = "click-8.1.4-py3-none-any.whl", hash = "sha256:2739815aaa5d2c986a88f1e9230c55e17f0caad3d958a5e13ad0797c166db9e3"},
{file = "click-8.1.4.tar.gz", hash = "sha256:b97d0c74955da062a7d4ef92fadb583806a585b2ea81958a81bd72726cbb8e37"},
]
[package.dependencies]
colorama = {version = "*", markers = "platform_system == \"Windows\""}
[[package]]
name = "colorama"
version = "0.4.6"
description = "Cross-platform colored terminal text."
optional = false
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7"
files = [
{file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"},
{file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"},
]
[metadata]
lock-version = "2.0"
python-versions = "^3.10"
content-hash = "6cfb3d71df95e3e0d9fbd3bd3803dcaea2cd2db898299bb891ccda039aede2bb"

17
pyproject.toml Normal file
View File

@ -0,0 +1,17 @@
[tool.poetry]
name = "lab_terminal"
version = "0.1.0"
description = ""
authors = ["Chris Proctor <chris@chrisproctor.net>"]
license = "MIT"
[tool.poetry.dependencies]
python = "^3.10"
click = "^8.1.4"
colorama = "^0.4.6"
[tool.poetry.dev-dependencies]
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

62
return_to_ship.py Normal file
View File

@ -0,0 +1,62 @@
# 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)