Mercurial > rinkhals
diff gamelib/animal.py @ 116:d539ef5a3333
Add basic chicken->egg cycle
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Wed, 02 Sep 2009 20:04:47 +0000 |
parents | 2b2007e231da |
children | d2b19131d537 |
line wrap: on
line diff
--- a/gamelib/animal.py Wed Sep 02 19:40:28 2009 +0000 +++ b/gamelib/animal.py Wed Sep 02 20:04:47 2009 +0000 @@ -65,11 +65,29 @@ image_right = imagecache.load_image('sprites/chkn.png', ("right_facing",)) Animal.__init__(self, image_left, image_right, pos) + self.egg = False + self.egg_counter = 0 def move(self, gameboard): """A free chicken will move away from other free chickens""" pass + def lay(self): + """See if the chicken lays an egg""" + if not self.egg: + self.egg = True + self.egg_counter = 2 + + 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 None + def _find_killable_fox(self, weapon, gameboard): """Choose a random fox within range of this weapon.""" killable_foxes = []