Save entities

This commit is contained in:
Yohann D'ANELLO
2020-11-19 00:10:37 +01:00
parent 657345e6f7
commit 81b20b72bc
5 changed files with 56 additions and 119 deletions

View File

@ -13,34 +13,16 @@ class Player(FightingEntity):
inventory: list
paths: Dict[Tuple[int, int], Tuple[int, int]]
## def __init__(self, maxhealth: int = 20, strength: int = 5,
## intelligence: int = 1, charisma: int = 1, dexterity: int = 1,
## constitution: int = 1, level: int = 1, current_xp: int = 0,
## max_xp: int = 10, *args, **kwargs) -> None:
## super().__init__(name="player", maxhealth=maxhealth, strength=strength,
## intelligence=intelligence, charisma=charisma,
## dexterity=dexterity, constitution=constitution,
## level=level, *args, **kwargs)
## self.current_xp = current_xp
## self.max_xp = max_xp
## self.inventory = list()
## self.paths = dict()
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
validkeys = {"current_xp" : 0,"max_xp" : 0}
for dictionary in args :
for key in validkeys :
if key in dictionary :
self.__setattr__(key, dictionary[key])
else :
self.__setattr__(key, validkeys[key])
for key in validkeys:
if key in kwargs :
self.__setattr__(key, kwargs[key])
else :
self.__setattr__(key, validkeys[key])
def __init__(self, maxhealth: int = 20, strength: int = 5,
intelligence: int = 1, charisma: int = 1, dexterity: int = 1,
constitution: int = 1, level: int = 1, current_xp: int = 0,
max_xp: int = 10, *args, **kwargs) -> None:
super().__init__(name="player", maxhealth=maxhealth, strength=strength,
intelligence=intelligence, charisma=charisma,
dexterity=dexterity, constitution=constitution,
level=level, *args, **kwargs)
self.current_xp = current_xp
self.max_xp = max_xp
self.inventory = list()
self.paths = dict()
@ -122,13 +104,12 @@ class Player(FightingEntity):
distances[(new_y, new_x)] = distances[(y, x)] + 1
queue.append((new_y, new_x))
self.paths = predecessors
def save_state(self) -> dict:
"""
Saves the state of the entity into a dictionary
"""
d = super().save_state()
d["type"] = "Player"
d["current_xp"] = self.current_xp
d["max_xp"] = self.max_xp
return d