for tile in self._tiles:
tile.draw(surface)
+ def update_card_pos(self, card_pos):
+ self.card_pos = card_pos
+ self.info.set_position(self.card_pos)
+ self.legal = self.card_pos in self.state.player.legal_moves()
+
def change_pos(self, offset):
tpos = (offset[0] + self.card_pos[0], offset[1] + self.card_pos[1])
if tpos[0] < 0 or tpos[1] < 0 or tpos[0] > 4 or tpos[1] > 4:
return False
- self.card_pos = tpos
- self.info.set_position(self.card_pos)
- self.legal = self.card_pos in self.state.player.legal_moves()
+ self.update_card_pos(tpos)
return True
+ def next_viable_pos(self):
+ moves = self.state.player.legal_moves()
+ try:
+ idx = moves.index(self.card_pos)
+ idx = (idx + 1) % len(moves)
+ except ValueError:
+ idx = 0
+ self.update_card_pos(moves[idx])
+
def handle_event(self, ev):
if self.state.gameboard.player_mode == ACT:
return super(BoardWidget, self).handle_event(ev)
elif ev.key in KEYS.RIGHT:
if self.change_pos((+1, 0)):
return finish_event()
+ elif ev.key in KEYS.SWITCH:
+ self.next_viable_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)