diff gamelib/animal.py @ 171:9ea53eb919cf

Make Animals accept Positions when created. move hatch watching from Chicken to Egg
author Neil Muller <drnlmuller@gmail.com>
date Thu, 03 Sep 2009 23:00:29 +0000
parents 0d6e23dcd3af
children ff168162974e
line wrap: on
line diff
--- a/gamelib/animal.py	Thu Sep 03 22:59:30 2009 +0000
+++ b/gamelib/animal.py	Thu Sep 03 23:00:29 2009 +0000
@@ -23,7 +23,10 @@
         self.image_left = image_left.copy()
         self._image_right = image_right
         self.image_right = image_right.copy()
-        self.pos = Position(tile_pos[0], tile_pos[1])
+        if hasattr(tile_pos, 'to_tuple'):
+            self.pos = tile_pos
+        else:
+            self.pos = Position(tile_pos[0], tile_pos[1])
         self.equipment = []
         self.abode = None
         self.facing = 'left'
@@ -105,7 +108,7 @@
         image_right = imagecache.load_image('sprites/chkn.png',
                 ("right_facing",))
         Animal.__init__(self, image_left, image_right, pos)
-        self.egg = False
+        self.egg = None
         self.egg_counter = 0
 
     def move(self, gameboard):
@@ -115,17 +118,12 @@
     def lay(self):
         """See if the chicken lays an egg"""
         if not self.egg:
-            self.egg = True
-            self.egg_counter = 2
+            self.egg = Egg(self.pos)
 
     def hatch(self):
         """See if we have an egg to hatch"""
         if self.egg:
-            self.egg_counter -= 1
-            if self.egg_counter == 0:
-                # Egg hatches
-                self.egg = False
-                return Chicken(self.pos.to_tuple())
+            return self.egg.hatch()
         return None
 
     def _find_killable_fox(self, weapon, gameboard):
@@ -160,9 +158,16 @@
     def __init__(self, pos):
         image = imagecache.load_image('sprites/egg.png')
         Animal.__init__(self, image, image, pos)
+        self.counter = 2
 
     # Eggs don't move
 
+    def hatch(self):
+        self.counter -= 1
+        if self.counter == 0:
+            return Chicken(self.pos)
+        return None
+
 class Fox(Animal):
     """A fox"""