From 1d7fb343a49306dae505b66c423810fcdd5d7fec Mon Sep 17 00:00:00 2001 From: Christian Heller <c.heller@plomlompom.de> Date: Sat, 6 Apr 2019 01:32:51 +0200 Subject: [PATCH] In client, ensure item pointer is always within range. --- new/example_client.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/new/example_client.py b/new/example_client.py index eb198e0..61f9233 100755 --- a/new/example_client.py +++ b/new/example_client.py @@ -524,11 +524,14 @@ class TUI: self.view = 'inventory' self.to_update['map'] = True elif self.view == 'pickable_items': + if len(self.game.world.pickable_items) < self.item_pointer + 1\ + and self.item_pointer > 0: + self.item_pointer = len(self.game.world.pickable_items) - 1 + while len(self.game.world.pickable_items) <= self.item_pointer: + self.item_pointer -= 1 if key == 'c': self.view = 'map' - elif key == 'j' and \ - len(self.game.world.pickable_items) > \ - self.item_pointer + 1: + elif key == 'j': self.item_pointer += 1 elif key == 'k' and self.item_pointer > 0: self.item_pointer -= 1 @@ -543,11 +546,12 @@ class TUI: continue self.to_update['map'] = True elif self.view == 'inventory': + if len(self.game.world.player_inventory) < self.item_pointer + 1\ + and self.item_pointer > 0: + self.item_pointer = len(self.game.world.player_inventory) - 1 if key == 'c': self.view = 'map' - elif key == 'j' and \ - len(self.game.world.player_inventory) > \ - self.item_pointer + 1: + elif key == 'j': self.item_pointer += 1 elif key == 'k' and self.item_pointer > 0: self.item_pointer -= 1 -- 2.30.2