Friendly entities are now a subclass of fighting entities, and can die. The T key is now used to talk to friendly entities
This commit is contained in:
@ -76,11 +76,19 @@ class Map:
|
||||
|
||||
def is_free(self, y: int, x: int) -> bool:
|
||||
"""
|
||||
Indicates that the case at the coordinates (y, x) is empty.
|
||||
Indicates that the tile at the coordinates (y, x) is empty.
|
||||
"""
|
||||
return 0 <= y < self.height and 0 <= x < self.width and \
|
||||
self.tiles[y][x].can_walk() and \
|
||||
not any(entity.x == x and entity.y == y for entity in self.entities)
|
||||
|
||||
def entity_is_present(self, y: int, x: int) -> bool:
|
||||
"""
|
||||
Indicates that the tile at the coordinates (y, x) contains a killable entity
|
||||
"""
|
||||
return 0 <= y < self.height and 0 <= x < self.width and \
|
||||
any(entity.x == x and entity.y == y and \
|
||||
entity.is_friendly() for entity in self.entities)
|
||||
|
||||
@staticmethod
|
||||
def load(filename: str) -> "Map":
|
||||
@ -431,7 +439,7 @@ class FightingEntity(Entity):
|
||||
|
||||
def keys(self) -> list:
|
||||
"""
|
||||
Returns a fighting entities specific attributes
|
||||
Returns a fighting entity's specific attributes
|
||||
"""
|
||||
return ["maxhealth", "health", "level", "strength",
|
||||
"intelligence", "charisma", "dexterity", "constitution"]
|
||||
@ -445,22 +453,18 @@ class FightingEntity(Entity):
|
||||
d[name] = getattr(self, name)
|
||||
return d
|
||||
|
||||
class FriendlyEntity(Entity):
|
||||
class FriendlyEntity(FightingEntity):
|
||||
"""
|
||||
Friendly entities are living entities which do not attack the player
|
||||
"""
|
||||
maxhealth: int
|
||||
health: int #Friendly entities can be killed
|
||||
dialogue_option : list
|
||||
|
||||
def __init__(self, maxhealth: int = 0, health: Optional[int] = None,
|
||||
*args, **kwargs) -> None:
|
||||
super().__init__(*args, **kwargs)
|
||||
self.maxhealth = maxhealth
|
||||
self.health = maxhealth if health is None else health
|
||||
|
||||
def talk_to(self, player : Any) -> str:
|
||||
a = randint(0,len(self.dialogue_option)-1)
|
||||
return "The sunflower said : "+self.dialogue_option[a]
|
||||
|
||||
return "The "+self.name+" said : "+self.dialogue_option[a]
|
||||
|
||||
def keys(self) -> list :
|
||||
"""
|
||||
Returns a friendly entity's specific attributes
|
||||
"""
|
||||
return ["maxhealth", "health", "dialogue_option"]
|
||||
|
Reference in New Issue
Block a user