Mercurial > rinkhals
comparison gamelib/animal.py @ 422:ab4fc3fe0f96
chickens scatter; chop wood
author | Adrianna Pińska <adrianna.pinska@gmail.com> |
---|---|
date | Sat, 21 Nov 2009 15:35:23 +0000 |
parents | f20ccd43a282 |
children | 97dd557504a2 |
comparison
equal
deleted
inserted
replaced
421:e65536ca215b | 422:ab4fc3fe0f96 |
---|---|
176 | 176 |
177 def _game_death(self, gameboard): | 177 def _game_death(self, gameboard): |
178 gameboard.remove_chicken(self) | 178 gameboard.remove_chicken(self) |
179 | 179 |
180 def move(self, gameboard): | 180 def move(self, gameboard): |
181 """A free chicken will move away from other free chickens""" | 181 """A free chicken will wander around aimlessly""" |
182 pass | 182 pos_x, pos_y = self.pos.to_tile_tuple() |
183 surrounds = [Position(pos_x + dx, pos_y + dy) for dx in [-1, 0, 1] for dy in [-1, 0, 1]] | |
184 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] | |
185 self.pos = pos_options[random.randint(0, len(pos_options)-1)] | |
186 | |
187 def chop(self, gameboard): | |
188 pos_x, pos_y = self.pos.to_tile_tuple() | |
189 surrounds = [Position(pos_x + dx, pos_y + dy) for dx in [-1, 0, 1] for dy in [-1, 0, 1]] | |
190 tree_options = [pos for pos in surrounds if gameboard.in_bounds(pos) and gameboard.tv.get(pos.to_tile_tuple()) == gameboard.WOODLAND] | |
191 if tree_options: | |
192 num_trees_to_cut = random.randint(0, len(tree_options)-1) | |
193 trees_to_cut = random.sample(tree_options, num_trees_to_cut) | |
194 for tree_pos in trees_to_cut: | |
195 gameboard.add_wood(5) | |
196 gameboard.tv.set(tree_pos.to_tile_tuple(), gameboard.GRASSLAND) | |
183 | 197 |
184 def lay(self, gameboard): | 198 def lay(self, gameboard): |
185 """See if the chicken lays an egg""" | 199 """See if the chicken lays an egg""" |
186 if self.abode and self.abode.building.HENHOUSE: | 200 if self.abode and self.abode.building.HENHOUSE: |
187 if not self.eggs: | 201 if not self.eggs: |