Instantiate entity attributes in __init__ rather than in the class definition
This commit is contained in:
@ -9,11 +9,13 @@ class Item(Entity):
|
||||
A class for items
|
||||
"""
|
||||
held: bool
|
||||
held_by: Optional["Player"]
|
||||
held_by: Optional[Player]
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
def __init__(self, held: bool = False, held_by: Optional[Player] = None,
|
||||
*args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.held = False
|
||||
self.held = held
|
||||
self.held_by = held_by
|
||||
|
||||
def drop(self, y: int, x: int) -> None:
|
||||
"""
|
||||
@ -40,8 +42,11 @@ class Heart(Item):
|
||||
"""
|
||||
A heart item to return health to the player
|
||||
"""
|
||||
name: str = "heart"
|
||||
healing: int = 5
|
||||
healing: int
|
||||
|
||||
def __init__(self, healing: int = 5, *args, **kwargs):
|
||||
super().__init__(name="heart", *args, **kwargs)
|
||||
self.healing = healing
|
||||
|
||||
def hold(self, player: "Player") -> None:
|
||||
"""
|
||||
@ -53,15 +58,16 @@ class Heart(Item):
|
||||
|
||||
class Bomb(Item):
|
||||
"""
|
||||
A bomb item intended to deal damage to ennemies at long range
|
||||
A bomb item intended to deal damage to enemies at long range
|
||||
"""
|
||||
name: str = "bomb"
|
||||
damage: int = 5
|
||||
exploding: bool
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.exploding = False
|
||||
def __init__(self, damage: int = 5, exploding: bool = False,
|
||||
*args, **kwargs):
|
||||
super().__init__(name="bomb", *args, **kwargs)
|
||||
self.damage = damage
|
||||
self.exploding = exploding
|
||||
|
||||
def drop(self, x: int, y: int) -> None:
|
||||
super().drop(x, y)
|
||||
|
Reference in New Issue
Block a user