Mercurial > rinkhals
comparison gamelib/gameboard.py @ 476:3dae0fc14009
Animals have their own gameboard references instead of lugging them around in params all the time.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Wed, 25 Nov 2009 17:44:32 +0000 |
parents | d4f04d81fe54 |
children | 6974048bf04a |
comparison
equal
deleted
inserted
replaced
475:d4f04d81fe54 | 476:3dae0fc14009 |
---|---|
237 self.reset_states() | 237 self.reset_states() |
238 self.toolbar.start_night() | 238 self.toolbar.start_night() |
239 self.spawn_foxes() | 239 self.spawn_foxes() |
240 self.eggs = 0 | 240 self.eggs = 0 |
241 for chicken in self.chickens.copy(): | 241 for chicken in self.chickens.copy(): |
242 chicken.start_night(self) | 242 chicken.start_night() |
243 self.toolbar.update_egg_counter(self.eggs) | 243 self.toolbar.update_egg_counter(self.eggs) |
244 self._cache_animal_positions() | 244 self._cache_animal_positions() |
245 | 245 |
246 def start_day(self): | 246 def start_day(self): |
247 self.day, self.night = True, False | 247 self.day, self.night = True, False |
250 self.toolbar.start_day() | 250 self.toolbar.start_day() |
251 self._pos_cache.clear() | 251 self._pos_cache.clear() |
252 self.advance_day() | 252 self.advance_day() |
253 self.clear_foxes() | 253 self.clear_foxes() |
254 for chicken in self.chickens.copy(): | 254 for chicken in self.chickens.copy(): |
255 chicken.start_day(self) | 255 chicken.start_day() |
256 self.redraw_counters() | 256 self.redraw_counters() |
257 | 257 |
258 def in_bounds(self, pos): | 258 def in_bounds(self, pos): |
259 """Check if a position is within the game boundaries""" | 259 """Check if a position is within the game boundaries""" |
260 if pos.x < 0 or pos.y < 0: | 260 if pos.x < 0 or pos.y < 0: |
338 do_sell(chick) | 338 do_sell(chick) |
339 | 339 |
340 def sell_one_egg(self, chicken): | 340 def sell_one_egg(self, chicken): |
341 if chicken.eggs: | 341 if chicken.eggs: |
342 self.add_cash(self.level.sell_price_egg) | 342 self.add_cash(self.level.sell_price_egg) |
343 chicken.remove_one_egg(self) | 343 chicken.remove_one_egg() |
344 return True | 344 return True |
345 return False | 345 return False |
346 | 346 |
347 def remove_eggs(self, num): | 347 def remove_eggs(self, num): |
348 self.eggs -= num | 348 self.eggs -= num |
451 try_pos = cand | 451 try_pos = cand |
452 break | 452 break |
453 if try_pos: | 453 if try_pos: |
454 chicken.unequip_by_name("Nest") | 454 chicken.unequip_by_name("Nest") |
455 self.relocate_animal(chicken, tile_pos=try_pos) | 455 self.relocate_animal(chicken, tile_pos=try_pos) |
456 chicken.remove_eggs(self) | 456 chicken.remove_eggs() |
457 | 457 |
458 def relocate_animal(self, chicken, tile_pos=None, place=None): | 458 def relocate_animal(self, chicken, tile_pos=None, place=None): |
459 assert((tile_pos, place) != (None, None)) | 459 assert((tile_pos, place) != (None, None)) |
460 if chicken.abode is not None: | 460 if chicken.abode is not None: |
461 chicken.abode.clear_occupant() | 461 chicken.abode.clear_occupant() |
749 | 749 |
750 def chickens_scatter(self): | 750 def chickens_scatter(self): |
751 """Chickens outside move around randomly a bit""" | 751 """Chickens outside move around randomly a bit""" |
752 for chicken in [chick for chick in self.chickens if chick.outside()]: | 752 for chicken in [chick for chick in self.chickens if chick.outside()]: |
753 old_pos = chicken.pos | 753 old_pos = chicken.pos |
754 chicken.move(self) | 754 chicken.move() |
755 self._pos_cache.update(old_pos, chicken, 'chicken') | 755 self._pos_cache.update(old_pos, chicken, 'chicken') |
756 | 756 |
757 def chickens_chop_wood(self): | 757 def chickens_chop_wood(self): |
758 """Chickens with axes chop down trees near them""" | 758 """Chickens with axes chop down trees near them""" |
759 for chicken in [chick for chick in self.chickens if chick.outside()]: | 759 for chicken in [chick for chick in self.chickens if chick.outside()]: |
760 chicken.chop(self) | 760 chicken.chop() |
761 self.calculate_wood_groat_exchange_rate() | 761 self.calculate_wood_groat_exchange_rate() |
762 | 762 |
763 def foxes_move(self): | 763 def foxes_move(self): |
764 over = True | 764 over = True |
765 for fox in self.foxes: | 765 for fox in self.foxes: |
766 old_pos = fox.pos | 766 old_pos = fox.pos |
767 fox.move(self) | 767 fox.move() |
768 if not fox.safe: | 768 if not fox.safe: |
769 over = False | 769 over = False |
770 self._pos_cache.update(old_pos, fox, 'fox') | 770 self._pos_cache.update(old_pos, fox, 'fox') |
771 return over | 771 return over |
772 | 772 |
773 def foxes_attack(self): | 773 def foxes_attack(self): |
774 for fox in self.foxes: | 774 for fox in self.foxes: |
775 fox.attack(self) | 775 fox.attack() |
776 | 776 |
777 def chickens_attack(self): | 777 def chickens_attack(self): |
778 for chicken in self.chickens: | 778 for chicken in self.chickens: |
779 chicken.attack(self) | 779 chicken.attack() |
780 | 780 |
781 def add_chicken(self, chicken): | 781 def add_chicken(self, chicken): |
782 self.chickens.add(chicken) | 782 self.chickens.add(chicken) |
783 if chicken.outside(): | 783 if chicken.outside(): |
784 self.tv.sprites.append(chicken) | 784 self.tv.sprites.append(chicken) |
851 self.wood += planks | 851 self.wood += planks |
852 self.toolbar.update_wood_counter(self.wood) | 852 self.toolbar.update_wood_counter(self.wood) |
853 | 853 |
854 def add_start_chickens(self, _map, tile, value): | 854 def add_start_chickens(self, _map, tile, value): |
855 """Add chickens as specified by the code layer""" | 855 """Add chickens as specified by the code layer""" |
856 chick = animal.Chicken((tile.tx, tile.ty)) | 856 chick = animal.Chicken((tile.tx, tile.ty), self) |
857 for equip_cls in equipment.EQUIP_MAP[value]: | 857 for equip_cls in equipment.EQUIP_MAP[value]: |
858 item = equip_cls() | 858 item = equip_cls() |
859 chick.equip(item) | 859 chick.equip(item) |
860 self.add_chicken(chick) | 860 self.add_chicken(chick) |
861 | 861 |
862 def _choose_fox(self, (x, y)): | 862 def _choose_fox(self, (x, y)): |
863 fox_cls = misc.WeightedSelection(self.level.fox_weightings).choose() | 863 fox_cls = misc.WeightedSelection(self.level.fox_weightings).choose() |
864 return fox_cls((x, y)) | 864 return fox_cls((x, y), self) |
865 | 865 |
866 def spawn_foxes(self): | 866 def spawn_foxes(self): |
867 """The foxes come at night, and this is where they come from.""" | 867 """The foxes come at night, and this is where they come from.""" |
868 # Foxes spawn just outside the map | 868 # Foxes spawn just outside the map |
869 x, y = 0, 0 | 869 x, y = 0, 0 |