comparison gamelib/animal.py @ 394:ad77b3b71b08

Fix crash when multiple foxes finish digging at the same time
author Neil Muller <drnlmuller@gmail.com>
date Thu, 12 Nov 2009 15:19:12 +0000
parents 463802281182
children 2d0ff46118e2
comparison
equal deleted inserted replaced
393:8104e82afd7a 394:ad77b3b71b08
424 self.tick = 5 424 self.tick = 5
425 self.dig_pos = dig_pos 425 self.dig_pos = dig_pos
426 426
427 def _make_hole(self, gameboard): 427 def _make_hole(self, gameboard):
428 """Make a hole in the fence""" 428 """Make a hole in the fence"""
429 gameboard.get_building(self.dig_pos.to_tuple()).damage(gameboard.tv) 429 fence = gameboard.get_building(self.dig_pos.to_tuple())
430 # Another fox could have made the same hole this turn
431 if fence:
432 fence.damage(gameboard.tv)
430 self.dig_pos = None 433 self.dig_pos = None
431 434
432 def move(self, gameboard): 435 def move(self, gameboard):
433 """Foxes will aim to move towards the closest henhouse or free 436 """Foxes will aim to move towards the closest henhouse or free
434 chicken""" 437 chicken"""
509 self.last_steps = [] 512 self.last_steps = []
510 513
511 def _make_hole(self, gameboard): 514 def _make_hole(self, gameboard):
512 """The Rinkhals eats fences""" 515 """The Rinkhals eats fences"""
513 fence = gameboard.get_building(self.dig_pos.to_tuple()) 516 fence = gameboard.get_building(self.dig_pos.to_tuple())
514 fence.remove(gameboard.tv) 517 if fence:
515 gameboard.remove_building(fence) 518 fence.remove(gameboard.tv)
519 gameboard.remove_building(fence)
516 self.dig_pos = None 520 self.dig_pos = None
517 521
518 def damage(self, gameboard): 522 def damage(self, gameboard):
519 """The Rinkhals is invincible!""" 523 """The Rinkhals is invincible!"""
520 return True 524 return True