From bf461cbd055b2f1a4c5b092f5e5f44a4c64f1a03 Mon Sep 17 00:00:00 2001 From: Ben Friedland Date: Mon, 7 Jan 2013 05:16:17 -0800 Subject: Orc battle at entrance of cave. Player now has hit_points. --- weatbag/__init__.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'weatbag/__init__.py') diff --git a/weatbag/__init__.py b/weatbag/__init__.py index 7c39d21..f9c34bf 100644 --- a/weatbag/__init__.py +++ b/weatbag/__init__.py @@ -8,6 +8,7 @@ class Player: self.name = name self.inventory = Counter() self.position = (0,0) + self.hit_points = 6 def has(self, item): "Does the player have any of item?" @@ -24,6 +25,24 @@ class Player: else: raise KeyError(item) + def state_string(self): + "Returns a string reporting the players health." + if self.hit_points >= 6: + return "feeling great" + elif self.hit_points == 5: + return "feeling good" + elif self.hit_points == 4: + return "feeling ok" + elif self.hit_points == 3: + return "feeling poor" + elif self.hit_points == 2: + return "feeling very unhealthy" + elif self.hit_points == 1: + return "nearly dead" + elif self.hit_points == 0: + return "dead" + + class World: def __init__(self): self.tiles = {} -- cgit v1.3 From bde94f80e518182888d944430bcfe7329d48e817 Mon Sep 17 00:00:00 2001 From: Ben Friedland Date: Mon, 7 Jan 2013 07:19:31 -0800 Subject: Else condition for reporting health is now a catch-all (in case they go into negative hit points). --- weatbag/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'weatbag/__init__.py') diff --git a/weatbag/__init__.py b/weatbag/__init__.py index f9c34bf..303962e 100644 --- a/weatbag/__init__.py +++ b/weatbag/__init__.py @@ -39,7 +39,7 @@ class Player: return "feeling very unhealthy" elif self.hit_points == 1: return "nearly dead" - elif self.hit_points == 0: + else: return "dead" -- cgit v1.3 From ead0301daaa6f07d9fc740050019bf204543f0ea Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Thu, 10 Jan 2013 16:45:18 +0000 Subject: Allow custom message when player attempts to move to nonexistent tile. Closes gh-7 --- doc/interface.rst | 6 ++++++ weatbag/__init__.py | 7 ++++--- weatbag/tiles/n3.py | 8 ++------ 3 files changed, 12 insertions(+), 9 deletions(-) (limited to 'weatbag/__init__.py') diff --git a/doc/interface.rst b/doc/interface.rst index 796fa4b..dd960b4 100644 --- a/doc/interface.rst +++ b/doc/interface.rst @@ -52,3 +52,9 @@ Your module should define a class called ``Tile``, with the following interface: :param player: the active :class:`~weatbag.Player` instance :param direction: the direction the player is trying to leave, as a single lowercase character, n/e/s/w + + .. attribute:: no_path_msg + + *Optional.* The message to display if the player attempts to leave in a + direction where there is no tile. The default message says "The undergrowth + in that direction is impassable. You turn back." diff --git a/weatbag/__init__.py b/weatbag/__init__.py index 9a743e0..511e8bc 100644 --- a/weatbag/__init__.py +++ b/weatbag/__init__.py @@ -101,7 +101,9 @@ def main(): name = input("What is your name? ") player = Player(name) interact(player) - + +no_path_msg = "The undergrowth in that direction is impassable. You turn back." + def interact(player): world = World() tile = world[player.position] @@ -120,8 +122,7 @@ def interact(player): try: tile = world[new_posn] except KeyError: - print("The undergrowth in that direction is impassable. " - "You turn back.") + print(getattr(tile, 'no_path_msg', no_path_msg)) else: player.position = new_posn tile.describe() diff --git a/weatbag/tiles/n3.py b/weatbag/tiles/n3.py index 7591110..125898b 100644 --- a/weatbag/tiles/n3.py +++ b/weatbag/tiles/n3.py @@ -51,13 +51,9 @@ class Tile: print("You manage to flee!") return True - if direction=='s': - return True - if direction=='n': - return True + return True - print("There is no path leading in that direction.") - return False + no_path_msg = "There is no path leading in that direction." def action(self, player, do): if do[0] == "flee": -- cgit v1.3