Short-circuit key checks.
authorSimon Cross <hodgestar@gmail.com>
Thu, 15 May 2014 19:41:21 +0000 (21:41 +0200)
committerSimon Cross <hodgestar@gmail.com>
Thu, 15 May 2014 19:41:21 +0000 (21:41 +0200)
naja/widgets/board.py

index d4d315af86d2e5a241dd87ac56d6d8fc54da2c1b..222da6cea9c1122270a45f1be823baa165e4e949 100644 (file)
@@ -3,7 +3,7 @@ Widget that holds the game tiles.
 """
 import pygame.locals as pgl
 
-from naja.constants import BOARD_SIZE, TILE_SIZE, KEYS, EXAMINE, ACT
+from naja.constants import BOARD_SIZE, TILE_SIZE, KEYS, ACT
 from naja.events import finish_event
 
 from naja.widgets.base import Widget
@@ -55,18 +55,18 @@ class BoardWidget(Widget):
             if ev.key in KEYS.UP:
                 if self.change_pos((0, -1)):
                     return finish_event()
-            if ev.key in KEYS.DOWN:
+            elif ev.key in KEYS.DOWN:
                 if self.change_pos((0, +1)):
                     return finish_event()
-            if ev.key in KEYS.LEFT:
+            elif ev.key in KEYS.LEFT:
                 if self.change_pos((-1, 0)):
                     return finish_event()
-            if ev.key in KEYS.RIGHT:
+            elif ev.key in KEYS.RIGHT:
                 if self.change_pos((+1, 0)):
                     return finish_event()
-            if (ev.key in KEYS.SELECT and
-                    self.state.player.set_position(self.card_pos)):
-                self.state.gameboard.change_mode(ACT)
-                self.info.set_position(self.card_pos)
-                return finish_event()
+            elif ev.key in KEYS.SELECT:
+                if self.state.player.set_position(self.card_pos):
+                    self.state.gameboard.change_mode(ACT)
+                    self.info.set_position(self.card_pos)
+                    return finish_event()
         return super(BoardWidget, self).handle_event(ev)