From 82ed3febfe0d961f5f33e86a1841bb86d368edeb Mon Sep 17 00:00:00 2001 From: Beej Jorgensen Date: Mon, 23 Jul 2018 14:56:42 -0700 Subject: [PATCH] new adv --- .gitignore | 4 ++- README.md | 13 +++++++-- src/adv.py | 74 ----------------------------------------------- src/adv/adv.py | 51 ++++++++++++++++++++++++++++++++ src/adv/player.py | 2 ++ src/adv/room.py | 2 ++ 6 files changed, 69 insertions(+), 77 deletions(-) delete mode 100644 src/adv.py create mode 100644 src/adv/adv.py create mode 100644 src/adv/player.py create mode 100644 src/adv/room.py diff --git a/.gitignore b/.gitignore index 1d74e21965..135933b631 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -.vscode/ +.vscode +*.pyc +__pycache__ \ No newline at end of file diff --git a/README.md b/README.md index 6bce0178cc..e7066d71fc 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ Learn the basics of Python with a pile of toy programs. Take a look in the `src/` directory. -NOTE: `adv.py` is for Day 2, so ignore it for today. +NOTE: `adv/` is for Day 2, so ignore it for today. Suggested order for implementing the toy programs: @@ -85,7 +85,16 @@ Suggested order for implementing the toy programs: Put it together into a bigger toy program: a simple text adventure! -This is in `src/adv.py`. Check it out! +This is in `src/adv/`. Check it out! + +* Put the Room class in room.py based on what you see in `adv.py`. + +* Put the Player class in `player.py`. + +* Follow the instructions `adv.py`. + +* Figure out what all those `.pyc` files are that appear after you successfully + run the program. Stretch goals: diff --git a/src/adv.py b/src/adv.py deleted file mode 100644 index ed039158cc..0000000000 --- a/src/adv.py +++ /dev/null @@ -1,74 +0,0 @@ -# Write a text adventure that allows the player to move from room to room by -# typing "n", "w", "s", or "e" for north, west, south, and east. - -# These are the existing rooms. Add more as you see fit. - -rooms = { - "outside": { - "name": "Outside Cave Entrance", - "description": "North of you, the cave mouth beckons.", - "n_to": "foyer", - }, - - "foyer": { - "name": "Foyer", - "description": "Dim light filters in from the south. Dusty passages run north and east.", - "n_to": "overlook", - "s_to": "outside", - "e_to": "narrow", - }, - - "overlook": { - "name": "Grand Overlook", - "description": """A steep cliff appears before you, falling -into the darkness. Ahead to the north, a light flickers in -the distance, but there is no way across the chasm.""", - "s_to": "foyer", - }, - - "narrow": { - "name": "Narrow Passage", - "description": "The narrow passage bends here from west to north. The smell of gold permeates the air.", - "w_to": "foyer", - "n_to": "treasure", - }, - - "treasure": { - "name": "Treasure Chamber", - "description": """You've found the long-lost treasure -chamber. Sadly, it has already been completely emptied by -earlier adventurers. The only exit is to the south.""", - "s_to": "narrow", - }, - -} - -""" template room to copy into code - "room": { - "name": "", - "description": "", - "n_to": "", - "s_to": "", - "e_to": "", - "w_to": "", - }, -""" - -# Write a class to hold player information, e.g. what room they are in currently - -# -# Main -# - -# Make a new player object that is currently in the 'outside' room. - -# Write a loop that: -# -# * Prints the current room name -# * Prints the current description (the textwrap module might be useful here). -# * Waits for user input and decides what to do. -# -# If the user enters a cardinal direction, attempt to move to the room there. -# Print an error message if the movement isn't allowed. -# -# If the user enters "q", quit the game. diff --git a/src/adv/adv.py b/src/adv/adv.py new file mode 100644 index 0000000000..c9e26b0f85 --- /dev/null +++ b/src/adv/adv.py @@ -0,0 +1,51 @@ +from room import Room + +# Declare all the rooms + +room = { + 'outside': Room("Outside Cave Entrance", + "North of you, the cave mount beckons"), + + 'foyer': Room("Foyer", """Dim light filters in from the south. Dusty +passages run north and east."""), + + 'overlook': Room("Grand Overlook", """A steep cliff appears before you, falling +into the darkness. Ahead to the north, a light flickers in +the distance, but there is no way across the chasm."""), + + 'narrow': Room("Narrow Passage", """The narrow passage bends here from west +to north. The smell of gold permeates the air."""), + + 'treasure': Room("Treasure Chamber", """You've found the long-lost treasure +chamber! Sadly, it has already been completely emptied by +earlier adventurers. The only exit is to the south."""), +} + + +# Link rooms together + +room['outside'].n_to = room['foyer'] +room['foyer'].s_to = room['outside'] +room['foyer'].n_to = room['overlook'] +room['foyer'].e_to = room['narrow'] +room['overlook'].s_to = room['foyer'] +room['narrow'].w_to = room['foyer'] +room['narrow'].n_to = room['treasure'] +room['treasure'].s_to = room['narrow'] + +# +# Main +# + +# Make a new player object that is currently in the 'outside' room. + +# Write a loop that: +# +# * Prints the current room name +# * Prints the current description (the textwrap module might be useful here). +# * Waits for user input and decides what to do. +# +# If the user enters a cardinal direction, attempt to move to the room there. +# Print an error message if the movement isn't allowed. +# +# If the user enters "q", quit the game. diff --git a/src/adv/player.py b/src/adv/player.py new file mode 100644 index 0000000000..d79a175029 --- /dev/null +++ b/src/adv/player.py @@ -0,0 +1,2 @@ +# Write a class to hold player information, e.g. what room they are in +# currently. diff --git a/src/adv/room.py b/src/adv/room.py new file mode 100644 index 0000000000..24c07ad4c8 --- /dev/null +++ b/src/adv/room.py @@ -0,0 +1,2 @@ +# Implement a class to hold room information. This should have name and +# description attributes. \ No newline at end of file