Up to this point, you've gotten your feet wet by working on a bunch of small Python programs. In this module, we're going to continue to solidify your Python chops by implementing a full-featured project according to a provided specification.
-
Put your Python basics into practice by implementing a text adventure game
-
Practice writing code that conforms to a specification
[x] _ Create the REPL command parser in adv.py which allows the player to move to rooms
in the four cardinal directions.
[x] _ Fill out Player and Room classes in player.py and room.py
[x] - Make rooms able to hold multiple items
[x] - Make the player able to carry multiple items
[x] - Add items to the game that the user can carry around
[x] - Add get [ITEM_NAME] and drop [ITEM_NAME] commands to the parser
The /src directory contains the files adv.py, which is where the main logic for the game should live, room.py, which will contain the definition of the Room class, and player.py, which will contain the definition of the Player class.
[x] _ Add a REPL parser to adv.py that accepts directional commands to move the player
[x] _ After each move, the REPL should print the name and description of the player's current room
[x] _ Valid commands are n, s, e and w which move the player North, South, East or West
[x] _ The parser should print an error if the player tries to move where there is no room.
[x] * Put the Room class in room.py based on what you see in adv.py.
[x] * The room should have name and description attributes.
[x] * The room should also have n_to, s_to, e_to, and w_to attributes
which point to the room in that respective direction.
[x] _ Put the Player class in player.py.
[x] _ Players should have a name and current_room attributes
[x] - Create a file called item.py and add an Item class in there.
[x] - The item should have name and description attributes.
[x] - Hint: the name should be one word for ease in parsing later.
[x] - This will be the base class for specialized item types to be declared later.
[x] - Add the ability to add items to rooms.
[x] - The Room class should be extended with a list that holds the Items
that are currently in that room.
[x] - Add functionality to the main loop that prints out all the items that are visible to the player when they are in that room.
[x] - Add capability to add Items to the player's inventory. The inventory can
also be a list of items "in" the player, similar to how Items can be in a
Room.
[x] - Add a new type of sentence the parser can understand: two words.
[x] - Until now, the parser could just understand one sentence form:
`verb`
such as "n" or "q".
[x] - But now we want to add the form:
`verb` `object`
such as "take coins" or "drop sword".
[x] - Split the entered command and see if it has 1 or 2 words in it to determine if it's the first or second form.
[x] - Implement support for the verb get followed by an Item name. This will be
used to pick up Items.
[x] - If the user enters get or take followed by an Item name, look at the
contents of the current Room to see if the item is there.
[x] - If it is there, remove it from the Room contents, and add it to the
Player contents.
[x] - If it's not there, print an error message telling the user so.
[x] - Add an `on_take` method to `Item`.
[x] - Call this method when the `Item` is picked up by the player.
[x] - `on_take` should print out "You have picked up [NAME]" when you pick up an item.
- The `Item` can use this to run additional code when it is picked up.
[x] - Add an `on_drop` method to `Item`. Implement it similar to `on_take`.
[x] - Implement support for the verb drop followed by an Item name. This is the
opposite of get/take.
[x] - Add the i and inventory commands that both show a list of items currently
carried by the player.
In arbitrary order:
-
Add more rooms
-
Add scoring
-
Subclass items into treasures
[x] - Add a subclass to Item called LightSource.
[x] - During world creation, add a lamp LightSource to a convenient Room.
[x] - Override on_drop in LightSource that tells the player "It's not wise to
drop your source of light!" if the player drops it. (But still lets them drop
it.)
[x] - Add an attribute to Room called is_light that is True if the Room is
naturally illuminated, or False if a LightSource is required to see what
is in the room.
[x] - Modify the main loop to test if there is light in the Room (i.e. if
is_light is True or there is a LightSource item in the Room's
contents or if there is a LightSource item in the Player's contents).
[x] - If there is light in the room, display name, description, and contents as normal.
[x] - If there isn't, print out "It's pitch black!" instead.
[x] - Hint: isinstance might help you figure out if there's a LightSource
among all the nearby Items.
[x] - Modify the get/take code to print "Good luck finding that in the dark!" if
the user tries to pick up an Item in the dark.
[x] - Add methods to notify items when they are picked up or dropped
[x] - Add light and darkness to the game
[x] - Add more items to the game.
- Add a way to win.
[x] - Add more to the parser.
-
Remember the last
Itemmentioned and substitute that if the user types "it" later, e.g.take sword drop it -
Add
Items with adjectives, like "rusty sword" and "silver sword".-
Modify the parser to handle commands like "take rusty sword" as well as "take sword".
- If the user is in a room that contains both the rusty sword and silver sword, and they type "take sword", the parser should say, "I don't know which you mean: rusty sword or silver sword."
-
-
Modify the code that calls
on_taketo check the return value. Ifon_takereturnsFalse, then don't continue picking up the object. (I.e. prevent the user from picking it up.)- This enables you to add logic to
on_taketo code things like "don't allow the user to pick up the dirt unless they're holding the shovel.
- This enables you to add logic to
-
Add monsters.
-
Add the
attackverb that allows you to specify a monster to attack. -
Add an
on_attackmethod to the monster class. -
Similar to the
on_takereturn value modification, above, haveon_attackprevent the attack from succeeding unless the user possesses asworditem. -
Come up with more stretch goals! The sky's the limit!
