# HG changeset patch # User Neil Muller # Date 1251924887 0 # Node ID d2b19131d537a3521ab2e0d9cdc4ac9ec90ddf9e # Parent 7b2660cc7861349f4650c7d82b13bec9a29f66d8 Don't continue the night if we're not doing anything anymore diff -r 7b2660cc7861 -r d2b19131d537 gamelib/animal.py --- 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) diff -r 7b2660cc7861 -r d2b19131d537 gamelib/engine.py --- 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) diff -r 7b2660cc7861 -r d2b19131d537 gamelib/gameboard.py --- 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)