Changeset 118:2c76ed47fc44


Ignore:
Timestamp:
Sep 2, 2009, 8:28:03 PM (11 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
Convert:
svn:b4e93282-eac8-4b8b-b765-0f5d36de2b68@119
Message:

Remove chicken respawn at day start. Handle eaten chickens in henhouses better

Location:
gamelib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • gamelib/engine.py

    r116 r118  
    5353        pygame.time.set_timer(MOVE_FOX_ID, 0)
    5454        self.game.gameboard.clear_foxes()
    55         self.game.gameboard.update_chickens()
    5655        sound.background_music("daytime.ogg")
    5756        self.game.gameboard.hatch_eggs()
  • gamelib/gameboard.py

    r116 r118  
    140140        self.buildings = []
    141141        self.cash = 0
     142        self.eggs = 0
    142143        self.killed_foxes = 0
    143144        self.add_cash(constants.STARTING_CASH)
    144145
    145146        self.fix_buildings()
     147
     148        self.add_some_chickens()
    146149
    147150    def create_disp(self):
     
    235238        if building:
    236239            # XXX: quick hack so egg loop triggers
    237             building.add_occupant(self.animal_to_place)
    238             if self.animal_to_place in self.tv.sprites:
    239                 self.tv.sprites.remove(self.animal_to_place)
    240             self.animal_to_place = None
    241             self.open_building_dialog(building)
     240            if self.animal_to_place:
     241                building.add_occupant(self.animal_to_place)
     242                if self.animal_to_place in self.tv.sprites:
     243                    self.tv.sprites.remove(self.animal_to_place)
     244                self.animal_to_place = None
     245                self.open_building_dialog(building)
    242246            return
    243247        if self.tv.get(tile_pos) == self.GRASSLAND:
     
    371375
    372376    def lay_eggs(self):
    373         eggs = 0
     377        self.eggs = 0
    374378        for building in self.buildings:
    375379            if building.NAME in [buildings.HenHouse.NAME]:
     
    378382                    chicken.lay()
    379383                    if chicken.egg:
    380                         eggs += 1
    381         self.toolbar.update_egg_counter(eggs)
     384                        self.eggs += 1
     385        self.toolbar.update_egg_counter(self.eggs)
    382386
    383387    def hatch_eggs(self):
    384         eggs = 0
    385388        for building in self.buildings:
    386389            if building.NAME in [buildings.HenHouse.NAME]:
     
    388391                    print 'Checking', chicken, chicken.egg, chicken.egg_counter
    389392                    new_chick = chicken.hatch()
    390                     if chicken.egg:
    391                         eggs += 1
    392393                    if new_chick:
     394                        self.eggs -= 1
    393395                        print 'hatching chicken %s in %s ' % (chicken, building)
    394396                        building.add_occupant(new_chick)
    395397                        self.add_chicken(new_chick)
    396         self.toolbar.update_egg_counter(eggs)
     398        self.toolbar.update_egg_counter(self.eggs)
    397399
    398400    def kill_fox(self, fox):
     
    410412    def remove_chicken(self, chick):
    411413        self.chickens.discard(chick)
     414        if chick.egg:
     415            self.eggs -= 1
     416            self.toolbar.update_egg_counter(self.eggs)
     417        if chick.abode:
     418            chick.abode.remove_occupant(chick)
    412419        self.toolbar.update_chicken_counter(len(self.chickens))
    413420        if chick in self.tv.sprites:
     
    424431        self.toolbar.update_cash_counter(self.cash)
    425432
    426     def update_chickens(self):
    427         """Update the chickens state at the start of the new day"""
    428         # Currently random chickens appear
    429         # Very simple, we walk around the tilemap, and, for each farm tile,
    430         # we randomly add a chicken (1 in 10 chance) until we have 5 chickens
    431         # or we run out of board
     433    def add_some_chickens(self):
     434        """Add some random chickens to start the game"""
    432435        x, y = 0, 0
    433436        width, height = self.tv.size
    434         while len(self.chickens) < 5:
     437        while len(self.chickens) < 10:
    435438            if x < width:
    436439                tile = self.tv.get((x, y))
Note: See TracChangeset for help on using the changeset viewer.