Exemplo n.º 1
0
def handle_user_event(bo):
    global run
    updated_board = bo

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False

        # click in cell
        elif event.type == pygame.MOUSEBUTTONUP:
            (row, col) = clicked_in_cell(pygame.mouse.get_pos())

            if bo.is_editable(row, col):
                updated_board.update_selected_cell((row, col))
                # print_board(updated_board)

        # keypress events
        elif event.type == pygame.KEYDOWN:
            selected_key = chr(event.key)

            # input number
            if re.match('\\d', selected_key) and bo.get_selected_cell():
                (selected_row, selected_col) = bo.get_selected_cell()

                if is_valid_placement(bo, selected_key, selected_row,
                                      selected_col):
                    updated_board.set_cell(selected_key, selected_row,
                                           selected_col)

            # clear cell
            elif selected_key == pygame.K_ESCAPE:
                if bo.is_editable(row, col):
                    updated_board.update_selected_cell(None)

    return updated_board
Exemplo n.º 2
0
 def test_is_not_valid_top_left(self):
     self.assertFalse(is_valid_placement(self.board, 8, 0, 0))
Exemplo n.º 3
0
 def test_is_valid_top_left(self):
     self.assertTrue(is_valid_placement(self.board, 5, 0, 0))