From 056ca5cca8cb1ec17a9083348bd62d2d3450e35f Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Fri, 4 Dec 2020 17:01:00 +0100 Subject: [PATCH] Ensure that the inventory is not empty before interacting with an item --- squirrelbattle/game.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/squirrelbattle/game.py b/squirrelbattle/game.py index f9f8881..ed576ed 100644 --- a/squirrelbattle/game.py +++ b/squirrelbattle/game.py @@ -123,12 +123,18 @@ class Game: self.inventory_menu.go_up() elif key == KeyValues.DOWN: self.inventory_menu.go_down() - elif key == KeyValues.USE: - self.inventory_menu.validate().use() - elif key == KeyValues.EQUIP: - self.inventory_menu.validate().equip() - elif key == KeyValues.DROP: - self.inventory_menu.validate().use() + if self.inventory_menu.values: + if key == KeyValues.USE: + self.inventory_menu.validate().use() + elif key == KeyValues.EQUIP: + self.inventory_menu.validate().equip() + elif key == KeyValues.DROP: + self.inventory_menu.validate().use() + + # Ensure that the cursor has a good position + self.inventory_menu.position = min(self.inventory_menu.position, + len(self.inventory_menu.values) + - 1) def handle_key_pressed_main_menu(self, key: KeyValues) -> None: """