Mercurial > rinkhals
comparison gamelib/animal.py @ 441:7b5e4b6dd889
fixed unarmed logging bug
author | Adrianna Pińska <adrianna.pinska@gmail.com> |
---|---|
date | Sat, 21 Nov 2009 18:55:58 +0000 |
parents | cf4b020e6385 |
children | 4efe57fcc1d7 |
comparison
equal
deleted
inserted
replaced
440:e945c4186ee5 | 441:7b5e4b6dd889 |
---|---|
196 pos_x, pos_y = self.pos.to_tile_tuple() | 196 pos_x, pos_y = self.pos.to_tile_tuple() |
197 surrounds = [Position(pos_x + dx, pos_y + dy) for dx in [-1, 0, 1] for dy in [-1, 0, 1]] | 197 surrounds = [Position(pos_x + dx, pos_y + dy) for dx in [-1, 0, 1] for dy in [-1, 0, 1]] |
198 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] | 198 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] |
199 self.pos = pos_options[random.randint(0, len(pos_options)-1)] | 199 self.pos = pos_options[random.randint(0, len(pos_options)-1)] |
200 | 200 |
201 def has_axe(self): | |
202 return bool([e for e in self.weapons() if item.NAME == "axe"]) | |
203 | |
201 def chop(self, gameboard): | 204 def chop(self, gameboard): |
202 pos_x, pos_y = self.pos.to_tile_tuple() | 205 if self.has_axe(): |
203 surrounds = [Position(pos_x + dx, pos_y + dy) for dx in [-1, 0, 1] for dy in [-1, 0, 1]] | 206 pos_x, pos_y = self.pos.to_tile_tuple() |
204 tree_options = [pos for pos in surrounds if gameboard.in_bounds(pos) and gameboard.tv.get(pos.to_tile_tuple()) == gameboard.WOODLAND] | 207 surrounds = [Position(pos_x + dx, pos_y + dy) for dx in [-1, 0, 1] for dy in [-1, 0, 1]] |
205 if tree_options: | 208 tree_options = [pos for pos in surrounds if gameboard.in_bounds(pos) and gameboard.tv.get(pos.to_tile_tuple()) == gameboard.WOODLAND] |
206 num_trees_to_cut = random.randint(1, len(tree_options)) | 209 if tree_options: |
207 trees_to_cut = random.sample(tree_options, num_trees_to_cut) | 210 num_trees_to_cut = random.randint(1, len(tree_options)) |
208 for tree_pos in trees_to_cut: | 211 trees_to_cut = random.sample(tree_options, num_trees_to_cut) |
209 gameboard.add_wood(5) | 212 for tree_pos in trees_to_cut: |
210 gameboard.tv.set(tree_pos.to_tile_tuple(), gameboard.GRASSLAND) | 213 gameboard.add_wood(5) |
214 gameboard.tv.set(tree_pos.to_tile_tuple(), gameboard.GRASSLAND) | |
211 | 215 |
212 def lay(self, gameboard): | 216 def lay(self, gameboard): |
213 """See if the chicken lays an egg""" | 217 """See if the chicken lays an egg""" |
214 if self.abode and self.abode.building.HENHOUSE: | 218 if self.abode and self.abode.building.HENHOUSE: |
215 if not self.eggs: | 219 if not self.eggs: |