diff --git a/squirrelbattle/entities/friendly.py b/squirrelbattle/entities/friendly.py index 88281a6..365bdbc 100644 --- a/squirrelbattle/entities/friendly.py +++ b/squirrelbattle/entities/friendly.py @@ -10,6 +10,12 @@ class Merchant(FriendlyEntity) : name = "Merchant" inventory = list hazel = int + + def keys(self) -> list : + """ + Returns a friendly entitie's specific attributes + """ + return ["maxhealth", "health", "inventory", "hazel"] def __init__(self, inventory : list, hazel : int = 75): super().__init__() @@ -22,8 +28,7 @@ class Merchant(FriendlyEntity) : and allow the player to buy/sell objects """ # TODO - - + class Sunflower(FriendlyEntity) : """ A friendly sunflower diff --git a/squirrelbattle/entities/player.py b/squirrelbattle/entities/player.py index 171f019..900a3bd 100644 --- a/squirrelbattle/entities/player.py +++ b/squirrelbattle/entities/player.py @@ -84,7 +84,10 @@ class Player(FightingEntity): elif entity.is_item(): entity.hold(self) elif entity.is_friendly(): - self.map.logs.add_message(entity.talk_to(self)) +# self.map.logs.add_message(entity.talk_to(self)) + self.map.logs.add_message(self.hit(entity)) + if entity.dead: + self.add_xp(randint(3, 7)) return super().check_move(y, x, move_if_possible) def recalculate_paths(self, max_distance: int = 8) -> None: diff --git a/squirrelbattle/enums.py b/squirrelbattle/enums.py index 024f167..17a4393 100644 --- a/squirrelbattle/enums.py +++ b/squirrelbattle/enums.py @@ -38,6 +38,7 @@ class KeyValues(Enum): RIGHT = auto() ENTER = auto() SPACE = auto() + T = auto() @staticmethod def translate_key(key: str, settings: Settings) -> Optional["KeyValues"]: @@ -60,4 +61,6 @@ class KeyValues(Enum): return KeyValues.ENTER elif key == ' ': return KeyValues.SPACE + elif key == 't': + return KeyValues.T return None diff --git a/squirrelbattle/game.py b/squirrelbattle/game.py index 44ad349..62ec243 100644 --- a/squirrelbattle/game.py +++ b/squirrelbattle/game.py @@ -24,6 +24,7 @@ class Game: """ map: Map player: Player + screen: Any # display_actions is a display interface set by the bootstrapper display_actions: Callable[[DisplayActions], None] @@ -61,6 +62,7 @@ class Game: We wait for the player's action, then we do what that should be done when the given key gets pressed. """ + self.screen = screen while True: # pragma no cover screen.erase() screen.refresh() @@ -106,6 +108,30 @@ class Game: self.map.tick() elif key == KeyValues.SPACE: self.state = GameMode.MAINMENU + elif key == KeyValues.T : + keykey = self.screen.getkey() + keykey = KeyValues.translate_key(keykey, self.settings) + if keykey == KeyValues.UP: + xp = self.player.x + yp = self.player.y+1 + elif keykey == KeyValues.DOWN: + xp = self.player.x + yp = self.player.y-1 + elif keykey == KeyValues.LEFT: + xp = self.player.x-1 + yp = self.player.y + elif keykey == KeyValues.RIGHT: + xp = self.player.x+1 + yp = self.player.y + else : + raise Exception(keykey) + if self.map.entity_is_present(yp, xp) : + for entity in self.map.entities : + if entity.is_friendly() and entity.x == xp and entity.y == yp : + msg = entity.talk_to(self.player) + self.logs.add_message(msg) + + def handle_key_pressed_main_menu(self, key: KeyValues) -> None: """ diff --git a/squirrelbattle/interfaces.py b/squirrelbattle/interfaces.py index 5c89172..db44675 100644 --- a/squirrelbattle/interfaces.py +++ b/squirrelbattle/interfaces.py @@ -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"]