generated from mwc/lab_terminal
Initial commit
This commit is contained in:
commit
77302f6e28
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
|
@ -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?
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
bag
|
||||
key.txt
|
||||
treasure.jpg
|
||||
.timer
|
||||
.log
|
||||
**/__pycache__/
|
|
@ -0,0 +1,39 @@
|
|||
# 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
|
||||
import sys
|
||||
sys.path.append('../../..')
|
||||
from fancy_printing import print_fancy
|
||||
|
||||
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 something shining brightly from within, so bright you can't quite make out what it is."
|
||||
]
|
||||
INSTRUCTIONS = [
|
||||
"You grab the treasure from the chest...it's so shiny! Make a bag and store your treasure inside, using the following commands:",
|
||||
"mkdir bag",
|
||||
"mv treasure.jpg bag",
|
||||
"Then get back to the surface. 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 .."
|
||||
]
|
||||
WRONG_CODE = [
|
||||
"nothing happens. Maybe next time."
|
||||
]
|
||||
|
||||
print_fancy(APPROACH_CHEST)
|
||||
guess = input(" > ")
|
||||
if guess.strip() == SECRET:
|
||||
print_fancy(CHEST_OPENS)
|
||||
print_fancy(INSTRUCTIONS)
|
||||
os.system('cp ./../../../.assets/fork.jpg treasure.jpg')
|
||||
else:
|
||||
print_fancy(WRONG_CODE)
|
|
@ -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/ _|
|
||||
|
||||
|
|
@ -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.
|
|
@ -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)
|
|
@ -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.
|
||||
|
|
@ -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)
|
|
@ -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.
|
|
@ -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 :)"])
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
# This file is automatically @generated by Poetry 2.0.0 and should not be changed by hand.
|
||||
|
||||
[[package]]
|
||||
name = "click"
|
||||
version = "8.1.8"
|
||||
description = "Composable command line interface toolkit"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
groups = ["main"]
|
||||
files = [
|
||||
{file = "click-8.1.8-py3-none-any.whl", hash = "sha256:63c132bbbed01578a06712a2d1f497bb62d9c1c0d329b7903a866228027263b2"},
|
||||
{file = "click-8.1.8.tar.gz", hash = "sha256:ed53c9d8990d83c2a27deae68e4ee337473f6330c040a31d4225c9574d16096a"},
|
||||
]
|
||||
|
||||
[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"
|
||||
groups = ["main"]
|
||||
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.1"
|
||||
python-versions = ">=3.10,<4.0"
|
||||
content-hash = "529d21bdfcb7ef92c5fa9f092bcc0b6eb3849fa52bb1ea59b3406787ab5dc05b"
|
|
@ -0,0 +1,22 @@
|
|||
[project]
|
||||
name = "lab-terminal"
|
||||
version = "0.1.0"
|
||||
description = ""
|
||||
authors = [
|
||||
{name = "Chris Proctor",email = "chris@chrisproctor.net"}
|
||||
]
|
||||
license = {text = "MIT"}
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.10,<4.0"
|
||||
dependencies = [
|
||||
"click (>=8.1.8,<9.0.0)",
|
||||
"colorama (>=0.4.6,<0.5.0)"
|
||||
]
|
||||
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
|
||||
[tool.poetry]
|
||||
package-mode = false
|
|
@ -0,0 +1,83 @@
|
|||
# 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 fancy_printing import print_fancy
|
||||
|
||||
LOG_FILE = ".log"
|
||||
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..."
|
||||
]
|
||||
EMPTY_BAG = [
|
||||
"You brought the bag back to the surface, but the treasure is not inside. You'll have to go back and open the chest again."
|
||||
]
|
||||
RUSTY_TREASURE = [
|
||||
"As you reach the surface, you look at the treasure in your hands. To your dismay, it has corroded into bits because you didn't keep it in its bag. You'll have to get another treasure from the chest...next time make sure you store it inside a bag."
|
||||
]
|
||||
VICTORY = [
|
||||
"You've made it back to the boat! The crew pulls you in. 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."
|
||||
]
|
||||
COMMANDS = [
|
||||
"As a reminder, here are some useful commands:",
|
||||
"To move a file or a directory from old to new: mv old new",
|
||||
"To create a directory named bag: mkdir bag"
|
||||
]
|
||||
|
||||
def win():
|
||||
print_fancy(VICTORY)
|
||||
win_time = datetime.now().isoformat()
|
||||
Path(LOG_FILE).write_text(f"finished the lab at {win_time}\n")
|
||||
|
||||
def find_file_in_path(path, file):
|
||||
results = list(Path(path).rglob(file))
|
||||
if results:
|
||||
return results[0]
|
||||
|
||||
def bag_is_here():
|
||||
return Path("bag").exists()
|
||||
|
||||
def treasure_is_here_in_bag():
|
||||
bag_path = Path("bag")
|
||||
treasure_in_bag_path = find_file_in_path(bag_path, "treasure.jpg")
|
||||
return bag_path.exists() and treasure_in_bag_path
|
||||
|
||||
def treasure_is_here_outside_of_bag():
|
||||
return Path("treasure.jpg").exists()
|
||||
|
||||
def find_treasure():
|
||||
return find_file_in_path("adventure", "treasure.jpg")
|
||||
|
||||
def find_bag():
|
||||
return find_file_in_path("adventure", "bag")
|
||||
|
||||
if treasure_is_here_in_bag():
|
||||
win()
|
||||
elif bag_is_here():
|
||||
rmtree("bag")
|
||||
print_fancy(EMPTY_BAG)
|
||||
elif treasure_is_here_outside_of_bag():
|
||||
Path("treasure.jpg").unlink()
|
||||
print_fancy(RUSTY_TREASURE)
|
||||
print_fancy(COMMANDS)
|
||||
elif not find_treasure():
|
||||
print_fancy(BEGINNING)
|
||||
elif find_bag():
|
||||
bag_path = find_bag()
|
||||
treasure_path = find_treasure()
|
||||
if treasure_path.is_relative_to(bag_path):
|
||||
message = f"You left your treasure bag at {bag_path}! Bring it back to the surface."
|
||||
else:
|
||||
message = f"You left your bag at {bag_path} and your treasure at {treasure_path}! Put the treasure in the bag, and then bring the bag to the surface."
|
||||
print_fancy([message])
|
||||
print_fancy(COMMANDS)
|
||||
else:
|
||||
treasure_path = find_treasure()
|
||||
message = f"You left your treasure at {treasure_path}! Create a bag, put the treasure inside, and bring the back back to the surface."
|
||||
print_fancy([message])
|
||||
print_fancy(COMMANDS)
|
Loading…
Reference in New Issue