summaryrefslogtreecommitdiffstats
path: root/weatbag
diff options
context:
space:
mode:
Diffstat (limited to 'weatbag')
-rw-r--r--weatbag/__init__.py19
-rw-r--r--weatbag/tiles/e2.py8
-rw-r--r--weatbag/tiles/n2.py4
-rw-r--r--weatbag/tiles/n3.py72
-rw-r--r--weatbag/words.py1
5 files changed, 103 insertions, 1 deletions
diff --git a/weatbag/__init__.py b/weatbag/__init__.py
index 72912c6..9a743e0 100644
--- a/weatbag/__init__.py
+++ b/weatbag/__init__.py
@@ -9,6 +9,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?"
@@ -25,6 +26,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"
+ else:
+ return "dead"
+
+
class World:
def __init__(self):
self.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 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")
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'}