From 61969c46e62ab17f423da0670638d1e5d9243c64 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Wed, 18 Nov 2020 14:29:54 +0100 Subject: [PATCH] Dead is an entity property --- dungeonbattle/interfaces.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/dungeonbattle/interfaces.py b/dungeonbattle/interfaces.py index d234578..00751e4 100644 --- a/dungeonbattle/interfaces.py +++ b/dungeonbattle/interfaces.py @@ -312,7 +312,6 @@ class FightingEntity(Entity): maxhealth: int health: int strength: int - dead: bool intelligence: int charisma: int dexterity: int @@ -322,16 +321,17 @@ class FightingEntity(Entity): def __init__(self): super().__init__() self.health = self.maxhealth - self.dead = False self.health = 0 self.strength = 0 - self.dead = False self.intelligence = 0 self.charisma = 0 self.dexterity = 0 self.constitution = 0 self.level = 1 - + + @property + def dead(self) -> bool: + return self.health <= 0 def hit(self, opponent: "FightingEntity") -> None: """ @@ -351,7 +351,6 @@ class FightingEntity(Entity): """ If a fighting entity has no more health, it dies and is removed """ - self.dead = True self.map.remove_entity(self) def keys(self) -> list: @@ -371,8 +370,8 @@ class FightingEntity(Entity): def recover_state(self, d : dict) -> None: """ - Loads the state of an entity from a dictionnary + Loads the state of an entity from a dictionary """ super().recover_state(d) for name in d.keys(): - self.__setattribute__(name, d[name]) + setattr(self, name, d[name])