diff options
| author | Thomas Kluyver <takowl@gmail.com> | 2013-01-05 17:12:31 +0000 |
|---|---|---|
| committer | Thomas Kluyver <takowl@gmail.com> | 2013-01-05 17:12:31 +0000 |
| commit | 3e50c8f35ab3a40231498109d7401e0097fb1dd1 (patch) | |
| tree | 8dce567ffe746ab7a46d482a0ef63c994d3d9502 | |
| parent | 76d1149e6725ca8a59799e0c1f2112d3cbab5afb (diff) | |
Add first tile in each cardinal direction.
| -rw-r--r-- | doc/interface.rst | 5 | ||||
| -rw-r--r-- | weatbag/tiles/e1.py | 25 | ||||
| -rw-r--r-- | weatbag/tiles/n1.py | 8 | ||||
| -rw-r--r-- | weatbag/tiles/s1.py | 7 | ||||
| -rw-r--r-- | weatbag/tiles/w1.py | 16 |
5 files changed, 59 insertions, 2 deletions
diff --git a/doc/interface.rst b/doc/interface.rst index e7505a4..796fa4b 100644 --- a/doc/interface.rst +++ b/doc/interface.rst @@ -36,7 +36,7 @@ Your module should define a class called ``Tile``, with the following interface: .. method:: action(player, do) Called when the player does something inside the tile. You need to - interpret the action and carry it out. + interpret the action and carry it out. Tile ``e1`` has a simple example. :param player: the active :class:`~weatbag.Player` instance :param action: list of strings - the player's input, split up into words, @@ -46,7 +46,8 @@ Your module should define a class called ``Tile``, with the following interface: *Optional.* Called when the player tries to leave the square. To let them leave, return `True`, or to prevent them, print an explanation and return - `False`. If the method isn't found, the player can always leave. + `False`. If the method isn't found, the player can always leave. Tile + ``w1`` has a simple example. :param player: the active :class:`~weatbag.Player` instance :param direction: the direction the player is trying to leave, as a single diff --git a/weatbag/tiles/e1.py b/weatbag/tiles/e1.py new file mode 100644 index 0000000..909f1b3 --- /dev/null +++ b/weatbag/tiles/e1.py @@ -0,0 +1,25 @@ +from weatbag import words + +class Tile: + def __init__(self): + self.contents = {'berries': 1} + + def describe(self): + print("The path crosses a small stream.") + if self.contents['berries']: + print("There are some berries hanging from a tree. They look edible. " + "If you're hungry enough, anyway.") + + def action(self, player, do): + if (do[0] in words.take) and ('berries' in do): + self.take_berries(player) + else: + print("Sorry, I don't understand.") + + def take_berries(self, player): + if self.contents['berries'] > 0: + self.contents['berries'] -= 1 + player.give('berries') + print("Reaching up, you pick the berries.") + else: + print("There are no berries here.") diff --git a/weatbag/tiles/n1.py b/weatbag/tiles/n1.py new file mode 100644 index 0000000..1484ca4 --- /dev/null +++ b/weatbag/tiles/n1.py @@ -0,0 +1,8 @@ +class Tile: + def describe(self): + print("A path runs through dense jungle. To the north, you can see the " + "entrance to a cave.") + + def action(self, player, do): + # Nothing to do here yet. + print("Sorry, I don't understand") diff --git a/weatbag/tiles/s1.py b/weatbag/tiles/s1.py new file mode 100644 index 0000000..efdc041 --- /dev/null +++ b/weatbag/tiles/s1.py @@ -0,0 +1,7 @@ +class Tile: + def describe(self): + print("You push through the undergrowth - there's hardly a path here at all.") + + def action(self, player, do): + # Nothing to do here yet. + print("Sorry, I don't understand") diff --git a/weatbag/tiles/w1.py b/weatbag/tiles/w1.py new file mode 100644 index 0000000..6f9119e --- /dev/null +++ b/weatbag/tiles/w1.py @@ -0,0 +1,16 @@ +class Tile: + + def describe(self): + print("The trees open out onto a beautiful beach. Small waves lap at the " + "sand. Ahead of you, the ocean stretches as far as you can see.") + + def action(self, player, do): + # Nothing to do here yet. + print("Sorry, I don't understand") + + def leave(self, player, direction): + if direction=='w': + print("You've forgotten how to swim") + return False + return True + |
