From ba68e6858457651f630d88ca9daf0936af725e8b Mon Sep 17 00:00:00 2001 From: eichhornchen Date: Sat, 5 Dec 2020 21:43:13 +0100 Subject: [PATCH] Added a Gamemode for selling interfaces, as well as the base of the player/merchant interaction, related to issue #18 --- squirrelbattle/entities/friendly.py | 4 ++-- squirrelbattle/entities/player.py | 6 ++++++ squirrelbattle/enums.py | 1 + squirrelbattle/game.py | 3 ++- squirrelbattle/interfaces.py | 8 +++++++- 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/squirrelbattle/entities/friendly.py b/squirrelbattle/entities/friendly.py index 365bdbc..9bdb3d0 100644 --- a/squirrelbattle/entities/friendly.py +++ b/squirrelbattle/entities/friendly.py @@ -11,7 +11,7 @@ class Merchant(FriendlyEntity) : inventory = list hazel = int - def keys(self) -> list : + def keys(self) -> list: """ Returns a friendly entitie's specific attributes """ @@ -22,7 +22,7 @@ class Merchant(FriendlyEntity) : self.inventory = inventory self.hazel = hazel - def talk_to(self, player : Player) -> None: + def talk_to(self, player : Player) -> str: """ This function is used to open the merchant's inventory in a menu, and allow the player to buy/sell objects diff --git a/squirrelbattle/entities/player.py b/squirrelbattle/entities/player.py index 900a3bd..46baacd 100644 --- a/squirrelbattle/entities/player.py +++ b/squirrelbattle/entities/player.py @@ -117,6 +117,12 @@ class Player(FightingEntity): queue.append((new_y, new_x)) self.paths = predecessors + def add_to_inventory(self, obj : Item) -> None : + """ + Adds an object to inventory + """ + self.inventory.append(obj) + def save_state(self) -> dict: """ Saves the state of the entity into a dictionary diff --git a/squirrelbattle/enums.py b/squirrelbattle/enums.py index 17a4393..e563600 100644 --- a/squirrelbattle/enums.py +++ b/squirrelbattle/enums.py @@ -26,6 +26,7 @@ class GameMode(Enum): PLAY = auto() SETTINGS = auto() INVENTORY = auto() + STORE = auto() class KeyValues(Enum): diff --git a/squirrelbattle/game.py b/squirrelbattle/game.py index 62ec243..ec54dae 100644 --- a/squirrelbattle/game.py +++ b/squirrelbattle/game.py @@ -130,7 +130,8 @@ class Game: if entity.is_friendly() and entity.x == xp and entity.y == yp : msg = entity.talk_to(self.player) self.logs.add_message(msg) - + if entity.is_merchant() : + self.state = GameMode.STORE def handle_key_pressed_main_menu(self, key: KeyValues) -> None: diff --git a/squirrelbattle/interfaces.py b/squirrelbattle/interfaces.py index db44675..c1f3078 100644 --- a/squirrelbattle/interfaces.py +++ b/squirrelbattle/interfaces.py @@ -329,6 +329,12 @@ class Entity: """ return isinstance(self, FriendlyEntity) + def is_merchant(self) -> bool: + """ + Is this entity a merchant? + """ + return isinstance(self, Merchant) + @property def translated_name(self) -> str: return _(self.name.replace("_", " ")) @@ -459,7 +465,7 @@ class FriendlyEntity(FightingEntity): """ dialogue_option : list - def talk_to(self, player : Any) -> str: + def talk_to(self, player : Any) -> str : a = randint(0,len(self.dialogue_option)-1) return "The "+self.name+" said : "+self.dialogue_option[a]