# HG changeset patch # User Adrianna PiƄska # Date 1252019471 0 # Node ID ff168162974e154aa156c22b3181a1445b14d1ec # Parent b2eed9977e352cca4c036fc89aeee837cc282325 armour gets damaged diff -r b2eed9977e35 -r ff168162974e gamelib/animal.py --- a/gamelib/animal.py Thu Sep 03 23:05:36 2009 +0000 +++ b/gamelib/animal.py Thu Sep 03 23:11:11 2009 +0000 @@ -30,7 +30,6 @@ self.equipment = [] self.abode = None self.facing = 'left' - self.lives = 1 def loop(self, tv, _sprite): ppos = tv.tile_to_view(self.pos.to_tuple()) @@ -92,12 +91,22 @@ def weapons(self): return [e for e in self.equipment if equipment.is_weapon(e)] + def armour(self): + return [e for e in self.equipment if equipment.is_armour(e)] + def covers(self, tile_pos): return tile_pos[0] == self.pos.x and tile_pos[1] == self.pos.y def outside(self): return self.abode is None + def survive_damage(self): + for a in self.armour(): + if not a.survive_damage(): + self.unequip(a) + return True + return False + class Chicken(Animal): """A chicken""" @@ -291,8 +300,7 @@ def _catch_chicken(self, chicken, gameboard): """Catch a chicken""" - chicken.lives -= 1 - if not chicken.lives > 0: + if not chicken.survive_damage(): sound.play_sound("kill-chicken.ogg") gameboard.remove_chicken(chicken) self.closest = None diff -r b2eed9977e35 -r ff168162974e gamelib/equipment.py --- a/gamelib/equipment.py Thu Sep 03 23:05:36 2009 +0000 +++ b/gamelib/equipment.py Thu Sep 03 23:11:11 2009 +0000 @@ -66,22 +66,33 @@ CHICKEN_IMAGE_FILE = 'sprites/equip_knife.png' class Armour(Equipment): + IS_ARMOUR = True DRAW_LAYER = 5 + def __init__(self): + super(Armour, self).__init__() + self.hitpoints = self.STARTING_HITPOINTS + def place(self, animal): """Give additional lives""" for eq in animal.equipment: if eq.NAME == self.NAME: return False - animal.lives += self.PROTECTION return True + def survive_damage(self): + self.hitpoints -= 1 + if self.hitpoints > 0: + self._sell_price = int(self._sell_price*self.hitpoints/float(self.hitpoints+1)) + return True + return False + class Helmet(Armour): NAME = "helmet" BUY_PRICE = 25 SELL_PRICE = 15 - PROTECTION = 1 + STARTING_HITPOINTS = 1 CHICKEN_IMAGE_FILE = 'sprites/helmet.png' @@ -90,7 +101,7 @@ BUY_PRICE = 100 SELL_PRICE = 75 - PROTECTION = 2 + STARTING_HITPOINTS = 2 CHICKEN_IMAGE_FILE = 'sprites/kevlar.png' @@ -101,6 +112,9 @@ def is_weapon(obj): return is_equipment(obj) and getattr(obj, 'IS_WEAPON', False) +def is_armour(obj): + return is_equipment(obj) and getattr(obj, 'IS_ARMOUR', False) + EQUIPMENT = [] for name in dir(): obj = eval(name) diff -r b2eed9977e35 -r ff168162974e gamelib/gameboard.py --- a/gamelib/gameboard.py Thu Sep 03 23:05:36 2009 +0000 +++ b/gamelib/gameboard.py Thu Sep 03 23:11:11 2009 +0000 @@ -563,8 +563,7 @@ def kill_fox(self, fox): if fox in self.foxes: - fox.lives -= 1 - if not fox.lives > 0: + if not fox.survive_damage(): self.killed_foxes += 1 self.toolbar.update_fox_counter(self.killed_foxes) self.add_cash(constants.SELL_PRICE_DEAD_FOX)