diff options
| author | Thomas Kluyver <takowl@gmail.com> | 2013-01-09 02:28:35 -0800 |
|---|---|---|
| committer | Thomas Kluyver <takowl@gmail.com> | 2013-01-09 02:28:35 -0800 |
| commit | 1da208f02a091c1dc9a9912d7066805a445d09bd (patch) | |
| tree | d99de9ea9b8d8073680f156395ee35022e37556a /weatbag/tiles | |
| parent | 3400844980917bb3d59da322a3e33f55f81afe12 (diff) | |
| parent | 6d1a17c456b15841763b953a1427e8bd856f2263 (diff) | |
Merge pull request #4 from ben174/master
Add new n3 tile with Orc battle at entrance of cave. Player now has hit_points.
Diffstat (limited to 'weatbag/tiles')
| -rw-r--r-- | weatbag/tiles/e2.py | 8 | ||||
| -rw-r--r-- | weatbag/tiles/n2.py | 4 | ||||
| -rw-r--r-- | weatbag/tiles/n3.py | 72 |
3 files changed, 83 insertions, 1 deletions
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 0f8da93..32e3ce4 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..7591110 --- /dev/null +++ b/weatbag/tiles/n3.py @@ -0,0 +1,72 @@ +from weatbag import words +import random + +class Tile: + def __init__(self): + self.enemy_dead = False + self.enemy_life = 2 + + def describe(self): + if not self.enemy_dead: + print("You encounter an orc! He's got a mean look, but you're a " + "strong one. You should be able to take him. Attack 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!") + return True + + 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": + self.leave(player, 's') + return + + if do[0] in words.attack: + self.player_swing(player) + self.enemy_swing(player) + + else: + print("Sorry, I don't understand") |
