|
| 1 | +# Intro to Python II |
| 2 | + |
| 3 | +## Goals |
| 4 | + |
| 5 | +* Solidify the Python basics by implementing a simple text adventure game |
| 6 | + |
| 7 | +## Summary |
| 8 | + |
| 9 | +* Add classes for rooms and the player |
| 10 | +* Add a simple parser that reads user input and performs actions |
| 11 | +* Add items to the game that the user can carry around |
| 12 | +* Make rooms able to hold multiple items |
| 13 | +* Make the player able to carry multiple items |
| 14 | +* Add two-word commands to the parser |
| 15 | +* Add the `get` and `drop` commands to the parser |
| 16 | + |
| 17 | +## Instructions |
| 18 | + |
| 19 | +This is in `src/adv/`. Check it out! |
| 20 | + |
| 21 | +* Put the Room class in room.py based on what you see in `adv.py`. |
| 22 | + |
| 23 | +* Put the Player class in `player.py`. |
| 24 | + |
| 25 | +* Create a file called `item.py` and add an `Item` class in there. |
| 26 | + |
| 27 | + * This will be the _base class_ for specialized item types to be declared |
| 28 | + later. |
| 29 | + |
| 30 | + * The item should have `name` and `description` attributes. |
| 31 | + |
| 32 | + * Hint: the name should be one word for ease in parsing later. |
| 33 | + |
| 34 | +* Add the ability to add items to rooms. |
| 35 | + |
| 36 | + * The `Room` class should be extended with a `list` that holds the `Item`s |
| 37 | + that are currently in that room. |
| 38 | + |
| 39 | + * Add functionality to the main loop that prints out all the items that are |
| 40 | + visible to the player when they are in that room. |
| 41 | + |
| 42 | +* Add capability to add `Item`s to the player's inventory. The inventory can |
| 43 | + also be a `list` of items "in" the player, similar to how `Item`s can be in a |
| 44 | + `Room`. |
| 45 | + |
| 46 | +* Add a new type of sentence the parser can understand: two words. |
| 47 | + |
| 48 | + * Until now, the parser could just understand one sentence form: |
| 49 | + |
| 50 | + `verb` |
| 51 | + |
| 52 | + such as "n" or "q". |
| 53 | + |
| 54 | + * But now we want to add the form: |
| 55 | + |
| 56 | + `verb` `object` |
| 57 | + |
| 58 | + such as "take coins" or "drop sword". |
| 59 | + |
| 60 | + * Split the entered command and see if it has 1 or 2 words in it to determine |
| 61 | + if it's the first or second form. |
| 62 | + |
| 63 | +* Implement support for the verb `get` followed by an `Item` name. This will be |
| 64 | + used to pick up `Item`s. |
| 65 | + |
| 66 | + * If the user enters `get` or `take` followed by an `Item` name, look at the |
| 67 | + contents of the current `Room` to see if the item is there. |
| 68 | + |
| 69 | + * If it is there, remove it from the `Room` contents, and add it to the |
| 70 | + `Player` contents. |
| 71 | + |
| 72 | + * If it's not there, print an error message telling the user so. |
| 73 | + |
| 74 | + * Add an `on_take` method to `Item`. |
| 75 | + |
| 76 | + * Call this method when the `Item` is picked up by the player. |
| 77 | + |
| 78 | + * The `Item` can use this to run additional code when it is picked up. |
| 79 | + |
| 80 | + * Add an `on_drop` method to `Item`. Implement it similar to `on_take`. |
| 81 | + |
| 82 | +* Implement support for the verb `drop` followed by an `Item` name. This is the |
| 83 | + opposite of `get`/`take`. |
| 84 | + |
| 85 | +* Add the `i` and `inventory` commands that both show a list of items currently |
| 86 | + carried by the player. |
| 87 | + |
| 88 | + |
| 89 | +## Stretch Goals |
| 90 | + |
| 91 | +In arbitrary order: |
| 92 | + |
| 93 | +* Add more rooms |
| 94 | + |
| 95 | +* Add scoring |
| 96 | + |
| 97 | +* Subclass items into treasures |
| 98 | + |
| 99 | +* Add a subclass to `Item` called `LightSource`. |
| 100 | + |
| 101 | + * During world creation, add a `lamp` `LightSource` to a convenient `Room`. |
| 102 | + |
| 103 | + * Override `on_drop` in `LightSource` that tells the player "It's not wise to |
| 104 | + drop your source of light!" if the player drops it. (But still lets them drop |
| 105 | + it.) |
| 106 | + |
| 107 | + * Add an attribute to `Room` called `is_light` that is `True` if the `Room` is |
| 108 | + naturally illuminated, or `False` if a `LightSource` is required to see what |
| 109 | + is in the room. |
| 110 | + |
| 111 | + * Modify the main loop to test if there is light in the `Room` (i.e. if |
| 112 | + `is_light` is `True` **or** there is a `LightSource` item in the `Room`'s |
| 113 | + contents **or** if there is a `LightSource` item in the `Player`'s contents). |
| 114 | + |
| 115 | + * If there is light in the room, display name, description, and contents as |
| 116 | + normal. |
| 117 | + |
| 118 | + * If there isn't, print out "It's pitch black!" instead. |
| 119 | + |
| 120 | + * Hint: `isinstance` might help you figure out if there's a `LightSource` |
| 121 | + among all the nearby `Item`s. |
| 122 | + |
| 123 | + * Modify the `get`/`take` code to print "Good luck finding that in the dark!" if |
| 124 | + the user tries to pick up an `Item` in the dark. |
| 125 | + |
| 126 | +* Add methods to notify items when they are picked up or dropped |
| 127 | + |
| 128 | +* Add light and darkness to the game |
| 129 | + |
| 130 | +* Add more items to the game. |
| 131 | + |
| 132 | +* Add a way to win. |
| 133 | + |
| 134 | +* Add more to the parser. |
| 135 | + |
| 136 | + * Remember the last `Item` mentioned and substitute that if the user types |
| 137 | + "it" later, e.g. |
| 138 | + |
| 139 | + ``` |
| 140 | + take sword |
| 141 | + drop it |
| 142 | + ``` |
| 143 | +
|
| 144 | + * Add `Item`s with adjectives, like "rusty sword" and "silver sword". |
| 145 | +
|
| 146 | + * Modify the parser to handle commands like "take rusty sword" as well as |
| 147 | + "take sword". |
| 148 | +
|
| 149 | + * If the user is in a room that contains both the rusty sword _and_ silver |
| 150 | + sword, and they type "take sword", the parser should say, "I don't know |
| 151 | + which you mean: rusty sword or silver sword." |
| 152 | +
|
| 153 | +* Modify the code that calls `on_take` to check the return value. If `on_take` |
| 154 | + returns `False`, then don't continue picking up the object. (I.e. prevent the |
| 155 | + user from picking it up.) |
| 156 | +
|
| 157 | + * This enables you to add logic to `on_take` to code things like "don't allow |
| 158 | + the user to pick up the dirt unless they're holding the shovel. |
| 159 | +
|
| 160 | +* Add monsters. |
| 161 | +
|
| 162 | +* Add the `attack` verb that allows you to specify a monster to attack. |
| 163 | +
|
| 164 | +* Add an `on_attack` method to the monster class. |
| 165 | +
|
| 166 | +* Similar to the `on_take` return value modification, above, have `on_attack` |
| 167 | + prevent the attack from succeeding unless the user possesses a `sword` item. |
| 168 | +
|
| 169 | +* Come up with more stretch goals! The sky's the limit! |
0 commit comments