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

@ -37,12 +37,13 @@ class Item(Entity):
self.map.remove_entity(self)
player.inventory.append(self)
def save_state(self) -> None:
def save_state(self) -> dict:
"""
Saves the state of the entity into a dictionary
"""
d = super().save_state()
d["held"] = self.held
return d
class Heart(Item):
@ -62,13 +63,6 @@ class Heart(Item):
player.health = min(player.maxhealth, player.health + self.healing)
self.map.remove_entity(self)
def save_state(self) -> None:
"""
Saves the state of the entity into a dictionary
"""
d = super().save_state()
d["type"] = "Heart"
class Bomb(Item):
"""
@ -96,10 +90,3 @@ class Bomb(Item):
if abs(e.x - self.x) + abs(e.y - self.y) <= 1 and \
isinstance(e, FightingEntity):
e.take_damage(self, self.damage)
def save_state(self) -> None:
"""
Saves the state of the entity into a dictionary
"""
d = super().save_state()
d["type"] = "Bomb"