Mercurial > rinkhals
comparison gamelib/gameboard.py @ 419:d110d55c8449
Move hatching logic into chickens.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Sat, 21 Nov 2009 15:22:41 +0000 |
parents | 9096c237928c |
children | e65536ca215b |
comparison
equal
deleted
inserted
replaced
418:2ccfadcae3b2 | 419:d110d55c8449 |
---|---|
368 self.reset_states() | 368 self.reset_states() |
369 self.toolbar.update_fin_tool(self.day) | 369 self.toolbar.update_fin_tool(self.day) |
370 self._cache_animal_positions() | 370 self._cache_animal_positions() |
371 self.spawn_foxes() | 371 self.spawn_foxes() |
372 self.eggs = 0 | 372 self.eggs = 0 |
373 for chicken in self.chickens: | 373 for chicken in self.chickens.copy(): |
374 chicken.start_night(self) | 374 chicken.start_night(self) |
375 self.toolbar.update_egg_counter(self.eggs) | 375 self.toolbar.update_egg_counter(self.eggs) |
376 | 376 |
377 def start_day(self): | 377 def start_day(self): |
378 self.day, self.night = True, False | 378 self.day, self.night = True, False |
380 self.reset_states() | 380 self.reset_states() |
381 self.toolbar.update_fin_tool(self.day) | 381 self.toolbar.update_fin_tool(self.day) |
382 self._pos_cache = { 'fox' : [], 'chicken' : []} | 382 self._pos_cache = { 'fox' : [], 'chicken' : []} |
383 self.advance_day() | 383 self.advance_day() |
384 self.clear_foxes() | 384 self.clear_foxes() |
385 self.hatch_eggs() | 385 for chicken in self.chickens.copy(): |
386 chicken.start_day(self) | |
387 self.toolbar.update_egg_counter(self.eggs) | |
386 | 388 |
387 def in_bounds(self, pos): | 389 def in_bounds(self, pos): |
388 """Check if a position is within the game boundaries""" | 390 """Check if a position is within the game boundaries""" |
389 if pos.x < 0 or pos.y < 0: | 391 if pos.x < 0 or pos.y < 0: |
390 return False | 392 return False |
874 | 876 |
875 def add_building(self, building): | 877 def add_building(self, building): |
876 self.buildings.append(building) | 878 self.buildings.append(building) |
877 self.tv.sprites.append(building, layer='buildings') | 879 self.tv.sprites.append(building, layer='buildings') |
878 | 880 |
879 def hatch_eggs(self): | 881 def place_hatched_chicken(self, new_chick, building): |
880 for building in self.buildings: | 882 try: |
881 if building.HENHOUSE: | 883 building.add_occupant(new_chick) |
882 for chicken in building.occupants(): | 884 self.add_chicken(new_chick) |
883 new_chick = chicken.hatch(self) | 885 new_chick.equip(equipment.Nest()) |
884 if new_chick: | 886 except buildings.BuildingFullError: |
885 try: | 887 # No space in the hen house, look nearby |
886 building.add_occupant(new_chick) | 888 for tile_pos in building.adjacent_tiles(): |
887 self.add_chicken(new_chick) | 889 if self.tv.get(tile_pos) != self.GRASSLAND: |
888 new_chick.equip(equipment.Nest()) | 890 continue |
889 except buildings.BuildingFullError: | 891 if self.get_outside_chicken(tile_pos) is None: |
890 # No space in the hen house, look nearby | 892 self.add_chicken(new_chick) |
891 for tile_pos in building.adjacent_tiles(): | 893 self.relocate_animal(new_chick, tile_pos=tile_pos) |
892 if self.tv.get(tile_pos) != self.GRASSLAND: | 894 break |
893 continue | 895 # if there isn't a space for the |
894 if self.get_outside_chicken(tile_pos) is None: | 896 # new chick it dies. :/ Farm life |
895 self.add_chicken(new_chick) | 897 # is cruel. |
896 self.relocate_animal(new_chick, tile_pos=tile_pos) | |
897 break | |
898 # if there isn't a space for the | |
899 # new chick it dies. :/ Farm life | |
900 # is cruel. | |
901 self.toolbar.update_egg_counter(self.eggs) | |
902 | 898 |
903 def kill_fox(self, fox): | 899 def kill_fox(self, fox): |
904 self.killed_foxes += 1 | 900 self.killed_foxes += 1 |
905 self.toolbar.update_fox_counter(self.killed_foxes) | 901 self.toolbar.update_fox_counter(self.killed_foxes) |
906 self.add_cash(self.level.sell_price_dead_fox) | 902 self.add_cash(self.level.sell_price_dead_fox) |