Add items in inventory

This commit is contained in:
Yohann D'ANELLO 2020-11-11 16:49:04 +01:00
parent f11fb31c28
commit d35331fdb0
2 changed files with 5 additions and 0 deletions

View File

@ -7,6 +7,7 @@ from ..interfaces import Entity, FightingEntity, Map
class Item(Entity): class Item(Entity):
held: bool held: bool
hold_by: Optional["Player"] hold_by: Optional["Player"]
can_be_in_inventory: bool = False
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
@ -22,10 +23,13 @@ class Item(Entity):
self.held = True self.held = True
self.hold_by = player self.hold_by = player
self.map.remove_entity(self) self.map.remove_entity(self)
if self.can_be_in_inventory:
player.inventory.append(self)
class Heart(Item): class Heart(Item):
name: str = "heart" name: str = "heart"
can_be_in_inventory: bool = False
healing: int = 5 healing: int = 5
def hold(self, player: "Player") -> None: def hold(self, player: "Player") -> None:

View File

@ -15,6 +15,7 @@ class Player(FightingEntity):
level: int = 1 level: int = 1
current_xp: int = 0 current_xp: int = 0
max_xp: int = 10 max_xp: int = 10
inventory: list = list()
paths: Dict[Tuple[int, int], Tuple[int, int]] paths: Dict[Tuple[int, int], Tuple[int, int]]
def move(self, y: int, x: int) -> None: def move(self, y: int, x: int) -> None: