Merchant menu is updated through its update function, and does not access globally to the Game instance

This commit is contained in:
Yohann D'ANELLO
2020-12-18 15:15:47 +01:00
parent 85870494a0
commit 46ce7c33bf
4 changed files with 18 additions and 11 deletions

View File

@@ -22,9 +22,6 @@ class Game:
"""
The game object controls all actions in the game.
"""
# Global instance of the game
INSTANCE: "Game"
map: Map
player: Player
screen: Any
@@ -35,8 +32,6 @@ class Game:
"""
Init the game.
"""
Game.INSTANCE = self
self.state = GameMode.MAINMENU
self.waiting_for_friendly_key = False
self.is_in_store_menu = True
@@ -170,6 +165,7 @@ class Game:
self.state = GameMode.STORE
self.is_in_store_menu = True
self.store_menu.update_merchant(entity)
self.display_actions(DisplayActions.UPDATE)
def handle_key_pressed_inventory(self, key: KeyValues) -> None:
"""
@@ -208,8 +204,10 @@ class Game:
menu.go_down()
elif key == KeyValues.LEFT:
self.is_in_store_menu = False
self.display_actions(DisplayActions.UPDATE)
elif key == KeyValues.RIGHT:
self.is_in_store_menu = True
self.display_actions(DisplayActions.UPDATE)
if menu.values and not self.player.dead:
if key == KeyValues.ENTER:
item = menu.validate()
@@ -220,7 +218,7 @@ class Game:
flag = item.be_sold(buyer, owner)
if not flag:
self.message = _("The buyer does not have enough money")
self.display_actions(DisplayActions.UPDATE)
self.display_actions(DisplayActions.UPDATE)
# Ensure that the cursor has a good position
menu.position = min(menu.position, len(menu.values) - 1)