Mercurial > rinkhals
diff gamelib/animal.py @ 396:19e583e5cdc0
Refactor for further move work
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Thu, 12 Nov 2009 21:31:52 +0000 |
parents | 2d0ff46118e2 |
children | 532f1ea476ff |
line wrap: on
line diff
--- a/gamelib/animal.py Thu Nov 12 21:14:21 2009 +0000 +++ b/gamelib/animal.py Thu Nov 12 21:31:52 2009 +0000 @@ -57,6 +57,11 @@ # Default is not to move pass + def attack(self, gameboard): + """Given the game state, attack a suitable target""" + # Default is not to attack + pass + def set_pos(self, tile_pos): """Move an animal to the given tile_pos.""" new_pos = Position(*tile_pos) @@ -364,8 +369,7 @@ self.hunting = False return self.pos if self.closest.pos == self.pos: - # Caught a chicken - self._catch_chicken(self.closest, gameboard) + # No need to move return self.pos if self.closest.pos.to_tile_tuple() == self.pos.to_tile_tuple(): # Only differ in z, so next step is in z @@ -376,6 +380,11 @@ return Position(self.pos.x, self.pos.y, new_z) return self._find_best_path_step(self.closest.pos, gameboard) + def attack(self, gameboard): + """Attack a chicken""" + if self.closest and self.closest.pos == self.pos: + self._catch_chicken(self.closest, gameboard) + def _catch_chicken(self, chicken, gameboard): """Catch a chicken""" chicken.damage(gameboard)