def _handle_input(self): poll = pygame.event.poll event = poll() while event: if event.type == QUIT: self.running = False break elif event.type == KEYDOWN: if event.key == K_ESCAPE: self.running = False break elif event.type == MOUSEBUTTONDOWN: position = pygame.mouse.get_pos() column = position[0] // 100 row = position[1] // 100 coords = Coordinates.from_matrix_coordinates((row, column)) piece = self.table.get(coords) if piece and piece.color == 'white': self._selected = (column, row) elif self._selected: selected_coords = Coordinates.from_matrix_coordinates( (self._selected[1], self._selected[0])) piece = self.table.get(selected_coords) if piece.can_move_to(coords): self.table.move_piece(selected_coords, coords) self._selected = None else: self._selected = None event = poll()
def __next__(self): if self._next >= 8: raise StopIteration() piece = self._row[self._next] coord = Coordinates.from_matrix_coordinates((self._row_number, self._next)) self._next += 1 return coord, piece