changeset 441:7b5e4b6dd889

fixed unarmed logging bug
author Adrianna Pińska <adrianna.pinska@gmail.com>
date Sat, 21 Nov 2009 18:55:58 +0000
parents e945c4186ee5
children 67b32a26dc57
files gamelib/animal.py gamelib/icons.py
diffstat 2 files changed, 16 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/animal.py	Sat Nov 21 18:42:15 2009 +0000
+++ b/gamelib/animal.py	Sat Nov 21 18:55:58 2009 +0000
@@ -198,16 +198,20 @@
         pos_options = [pos for pos in surrounds if gameboard.in_bounds(pos) and gameboard.tv.get(pos.to_tile_tuple()) == gameboard.GRASSLAND and not gameboard.get_outside_chicken(pos.to_tile_tuple())] + [self.pos]
         self.pos = pos_options[random.randint(0, len(pos_options)-1)]
 
+    def has_axe(self):
+        return bool([e for e in self.weapons() if item.NAME == "axe"])
+
     def chop(self, gameboard):
-        pos_x, pos_y = self.pos.to_tile_tuple()
-        surrounds = [Position(pos_x + dx, pos_y + dy) for dx in [-1, 0, 1] for dy in [-1, 0, 1]]
-        tree_options = [pos for pos in surrounds if gameboard.in_bounds(pos) and gameboard.tv.get(pos.to_tile_tuple()) == gameboard.WOODLAND]
-        if tree_options:
-            num_trees_to_cut = random.randint(1, len(tree_options))
-            trees_to_cut = random.sample(tree_options, num_trees_to_cut)
-            for tree_pos in trees_to_cut:
-                gameboard.add_wood(5)
-                gameboard.tv.set(tree_pos.to_tile_tuple(), gameboard.GRASSLAND)
+        if self.has_axe():
+            pos_x, pos_y = self.pos.to_tile_tuple()
+            surrounds = [Position(pos_x + dx, pos_y + dy) for dx in [-1, 0, 1] for dy in [-1, 0, 1]]
+            tree_options = [pos for pos in surrounds if gameboard.in_bounds(pos) and gameboard.tv.get(pos.to_tile_tuple()) == gameboard.WOODLAND]
+            if tree_options:
+                num_trees_to_cut = random.randint(1, len(tree_options))
+                trees_to_cut = random.sample(tree_options, num_trees_to_cut)
+                for tree_pos in trees_to_cut:
+                    gameboard.add_wood(5)
+                    gameboard.tv.set(tree_pos.to_tile_tuple(), gameboard.GRASSLAND)
 
     def lay(self, gameboard):
         """See if the chicken lays an egg"""
--- a/gamelib/icons.py	Sat Nov 21 18:42:15 2009 +0000
+++ b/gamelib/icons.py	Sat Nov 21 18:55:58 2009 +0000
@@ -6,6 +6,9 @@
 
 KILLED_FOX = Image(imagecache.load_image('icons/killed_fox.png'))
 CHKN_ICON = Image(imagecache.load_image('icons/chkn.png'))
+EGG_ICON = Image(imagecache.load_image('icons/egg.png'))
+WOOD_ICON = Image(imagecache.load_image('icons/wood.png'))
+GROATS_ICON = Image(imagecache.load_image('icons/groats.png'))
 EMPTY_NEST_ICON = Image(imagecache.load_image('sprites/nest.png'))
 
 def animal_icon(animal):