Mercurial > rinkhals
changeset 122:d2b19131d537
Don't continue the night if we're not doing anything anymore
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Wed, 02 Sep 2009 20:54:47 +0000 |
parents | 7b2660cc7861 |
children | a7d803275a23 |
files | gamelib/animal.py gamelib/engine.py gamelib/gameboard.py |
diffstat | 3 files changed, 15 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/gamelib/animal.py Wed Sep 02 20:54:45 2009 +0000 +++ b/gamelib/animal.py Wed Sep 02 20:54:47 2009 +0000 @@ -150,6 +150,7 @@ self.hunting = True self.dig_pos = None self.tick = 0 + self.safe = False def _cost_tile(self, pos, gameboard): if gameboard.in_bounds(pos): @@ -215,6 +216,7 @@ self.landmarks.pop() # Moving to the next landmark else: # Safely back at the start + self.safe = True return self.pos return self._find_best_path_step(self.landmarks[-1], gameboard)
--- a/gamelib/engine.py Wed Sep 02 20:54:45 2009 +0000 +++ b/gamelib/engine.py Wed Sep 02 20:54:47 2009 +0000 @@ -104,7 +104,9 @@ self.cycle_count += 1 if self.cycle_count > NIGHT_LENGTH: return pygame.event.post(START_DAY) - return self.game.gameboard.move_foxes() + if self.game.gameboard.move_foxes(): + # All foxes are gone/safe, so dawn happens + return pygame.event.post(START_DAY) elif e.type is not QUIT: self.game.gameboard.event(e)
--- a/gamelib/gameboard.py Wed Sep 02 20:54:45 2009 +0000 +++ b/gamelib/gameboard.py Wed Sep 02 20:54:47 2009 +0000 @@ -354,10 +354,20 @@ self.foxes = set() # Remove all the foxes def move_foxes(self): + """Move the foxes. + + We return True if there are no more foxes to move or all the + foxes are safely back. This end's the night""" + if not self.foxes: + return True + over = True for fox in self.foxes: fox.move(self) + if not fox.safe: + over = False for chicken in self.chickens: chicken.attack(self) + return over def add_chicken(self, chicken): self.chickens.add(chicken)