Mercurial > rinkhals
comparison 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 |
comparison
equal
deleted
inserted
replaced
115:2b2007e231da | 116:d539ef5a3333 |
---|---|
63 def __init__(self, pos): | 63 def __init__(self, pos): |
64 image_left = imagecache.load_image('sprites/chkn.png') | 64 image_left = imagecache.load_image('sprites/chkn.png') |
65 image_right = imagecache.load_image('sprites/chkn.png', | 65 image_right = imagecache.load_image('sprites/chkn.png', |
66 ("right_facing",)) | 66 ("right_facing",)) |
67 Animal.__init__(self, image_left, image_right, pos) | 67 Animal.__init__(self, image_left, image_right, pos) |
68 self.egg = False | |
69 self.egg_counter = 0 | |
68 | 70 |
69 def move(self, gameboard): | 71 def move(self, gameboard): |
70 """A free chicken will move away from other free chickens""" | 72 """A free chicken will move away from other free chickens""" |
71 pass | 73 pass |
74 | |
75 def lay(self): | |
76 """See if the chicken lays an egg""" | |
77 if not self.egg: | |
78 self.egg = True | |
79 self.egg_counter = 2 | |
80 | |
81 def hatch(self): | |
82 """See if we have an egg to hatch""" | |
83 if self.egg: | |
84 self.egg_counter -= 1 | |
85 if self.egg_counter == 0: | |
86 # Egg hatches | |
87 self.egg = False | |
88 return Chicken(self.pos.to_tuple()) | |
89 return None | |
72 | 90 |
73 def _find_killable_fox(self, weapon, gameboard): | 91 def _find_killable_fox(self, weapon, gameboard): |
74 """Choose a random fox within range of this weapon.""" | 92 """Choose a random fox within range of this weapon.""" |
75 killable_foxes = [] | 93 killable_foxes = [] |
76 for fox in gameboard.foxes: | 94 for fox in gameboard.foxes: |