From: Simon Cross Date: Thu, 15 May 2014 19:41:21 +0000 (+0200) Subject: Short-circuit key checks. X-Git-Tag: 0.1~265 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=cfe014c380c8a5be0062f5bfcd37cc053dd6d56f;p=naja.git Short-circuit key checks. --- diff --git a/naja/widgets/board.py b/naja/widgets/board.py index d4d315a..222da6c 100644 --- a/naja/widgets/board.py +++ b/naja/widgets/board.py @@ -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)