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/tiles/e2.py | 8 +++++++ weatbag/tiles/n2.py | 4 +++- weatbag/tiles/n3.py | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 weatbag/tiles/n3.py (limited to 'weatbag/tiles') diff --git a/weatbag/tiles/e2.py b/weatbag/tiles/e2.py index 2a8690b..ca66475 100644 --- a/weatbag/tiles/e2.py +++ b/weatbag/tiles/e2.py @@ -22,6 +22,14 @@ class Tile: def action(self, player, do): if do[0] == "guess" and self.contents['unlit torch']: try: + if do[1] == "correctly": + print("You sly dog, you!") + print("The dwarf hands you a torch! " + "He then suddenly vanishes, leaving behind a pile of dust.") + self.contents['unlit torch'] -= 1 + player.give('unlit torch') + return + guess = int(do[1]) self.guess_count += 1 if guess > self.lucky_number: diff --git a/weatbag/tiles/n2.py b/weatbag/tiles/n2.py index b903ed3..a9bca43 100644 --- a/weatbag/tiles/n2.py +++ b/weatbag/tiles/n2.py @@ -2,7 +2,9 @@ from weatbag import words class Tile: def describe(self): - print("You are standing in the mouth of a cave. The air feels cool.") + print("You are standing in the mouth of a cave. The air feels cool and " + "is filled with the stench of rotting flesh. " + "A dark path leads to the north. An exit to the south.") def leave(self, player, direction): if direction=='s': diff --git a/weatbag/tiles/n3.py b/weatbag/tiles/n3.py new file mode 100644 index 0000000..e0a1a4a --- /dev/null +++ b/weatbag/tiles/n3.py @@ -0,0 +1,67 @@ +from weatbag import words +import random + +class Tile: + def __init__(self): + self.enemy_dead = False + self.enemy_life = 2 + self.player_life = 4 + + def describe(self): + if not self.enemy_dead: + print("You encounter an orc! He's got a mean look, but you're a " + "strong lad. You should be able to take him. Swing or flee?") + else: + print("You see an orc corpse here.") + + + def enemy_swing(self, player): + if self.enemy_dead: + return + print("The enemy takes a swing at you!") + hit = random.choice((True,False)) + if hit: + print("He hits you!") + player.hit_points -= 1 + self.report_player_state(player) + else: + print("He misses!") + + def player_swing(self, player): + hit = random.choice((True,False)) + if hit: + print("You hit him!") + self.enemy_life -= 1 + else: + print("You miss!") + + if self.enemy_life == 0: + print("You have killed the orc!") + self.enemy_dead = True + + def report_player_state(self, player): + print("You are %s" % (player.state_string())) + + def leave(self, player, direction): + if not self.enemy_dead: + if not random.choice((True,False)): + print("The orc blocks your way!") + self.enemy_swing(player) + return False + else: + print("You manage to flee!") + + if direction=='s': + return True + + def action(self, player, do): + if do[0] == "flee": + self.leave(player, 's') + return + + if do[0] == "swing": + self.player_swing(player) + self.enemy_swing(player) + + else: + print("Sorry, I don't understand") -- cgit v1.3 From d531a0e0a763b2066bc94446df3dc5425538a1fc Mon Sep 17 00:00:00 2001 From: Ben Friedland Date: Mon, 7 Jan 2013 05:27:38 -0800 Subject: Removed additional player_life attribute from n3 tile. It's been moved to Player class. --- weatbag/tiles/n3.py | 1 - 1 file changed, 1 deletion(-) (limited to 'weatbag/tiles') diff --git a/weatbag/tiles/n3.py b/weatbag/tiles/n3.py index e0a1a4a..93933d8 100644 --- a/weatbag/tiles/n3.py +++ b/weatbag/tiles/n3.py @@ -5,7 +5,6 @@ class Tile: def __init__(self): self.enemy_dead = False self.enemy_life = 2 - self.player_life = 4 def describe(self): if not self.enemy_dead: -- cgit v1.3 From a537a2b9c2ac6f9816368c4284d9b8073e94a8ea Mon Sep 17 00:00:00 2001 From: Ben Friedland Date: Mon, 7 Jan 2013 05:54:05 -0800 Subject: Support for attack words. --- weatbag/tiles/n3.py | 4 ++-- weatbag/words.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'weatbag/tiles') diff --git a/weatbag/tiles/n3.py b/weatbag/tiles/n3.py index 93933d8..a290372 100644 --- a/weatbag/tiles/n3.py +++ b/weatbag/tiles/n3.py @@ -9,7 +9,7 @@ class Tile: def describe(self): if not self.enemy_dead: print("You encounter an orc! He's got a mean look, but you're a " - "strong lad. You should be able to take him. Swing or flee?") + "strong one. You should be able to take him. Attack or flee?") else: print("You see an orc corpse here.") @@ -58,7 +58,7 @@ class Tile: self.leave(player, 's') return - if do[0] == "swing": + if do[0] in words.attack: self.player_swing(player) self.enemy_swing(player) diff --git a/weatbag/words.py b/weatbag/words.py index 11ede7d..25f762e 100644 --- a/weatbag/words.py +++ b/weatbag/words.py @@ -14,6 +14,7 @@ fight = {'fight', 'kill', 'hit', 'attack'} drop = {'drop'} take = {'pick', 'take', 'get', 'collect'} look = {'look', 'inspect', 'examine'} +attack = {'attack', 'swing', 'hit', 'punch', 'fight'} inventory = {'inventory', 'possessions', 'belongings', 'bag'} surroundings = {'surroundings', 'around', 'scenery'} -- cgit v1.3 From 3276c1c553e80780e2cd88032b61b923517dc115 Mon Sep 17 00:00:00 2001 From: Ben Friedland Date: Mon, 7 Jan 2013 06:58:47 -0800 Subject: leave method returns True if they manage to flee --- weatbag/tiles/n3.py | 1 + 1 file changed, 1 insertion(+) (limited to 'weatbag/tiles') diff --git a/weatbag/tiles/n3.py b/weatbag/tiles/n3.py index a290372..992d7f2 100644 --- a/weatbag/tiles/n3.py +++ b/weatbag/tiles/n3.py @@ -49,6 +49,7 @@ class Tile: return False else: print("You manage to flee!") + return True if direction=='s': return True -- cgit v1.3 From 6d1a17c456b15841763b953a1427e8bd856f2263 Mon Sep 17 00:00:00 2001 From: Ben Friedland Date: Mon, 7 Jan 2013 22:24:09 -0800 Subject: Fixed leave condition at cave entrance. --- weatbag/tiles/n3.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'weatbag/tiles') diff --git a/weatbag/tiles/n3.py b/weatbag/tiles/n3.py index 992d7f2..7591110 100644 --- a/weatbag/tiles/n3.py +++ b/weatbag/tiles/n3.py @@ -53,6 +53,11 @@ class Tile: if direction=='s': return True + if direction=='n': + return True + + print("There is no path leading in that direction.") + return False def action(self, player, do): if do[0] == "flee": -- cgit v1.3