home · contact · privacy
In client, ensure item pointer is always within range.
authorChristian Heller <c.heller@plomlompom.de>
Fri, 5 Apr 2019 23:32:51 +0000 (01:32 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Fri, 5 Apr 2019 23:32:51 +0000 (01:32 +0200)
new/example_client.py

index eb198e0584da58e14063df126487fd1b2eaa4448..61f9233d60dea76c1a1a83ab13e7aa7f2a1ebc59 100755 (executable)
@@ -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