Exemplo n.º 1
0
                        selectedSquare = move_y
                if event.key == K_LEFT:
                    move_x = selectedSquare - 1
                    if 0 <= move_x <= 80 and selectedSquare % 9 != 0:  # ignoring suggestion for readability.
                        selectedSquare = move_x
                if event.key == K_RIGHT:
                    move_x = selectedSquare + 1
                    if 0 <= move_x <= 80 and selectedSquare % 9 != 8:
                        selectedSquare = move_x
                if event.key in numberMap:
                    puzzle.set_number(selectedSquare, numberMap[event.key])
                if event.key == K_0 or event.key == K_KP0 or event.key == K_DELETE or event.key == K_BACKSPACE:
                    puzzle.set_number(selectedSquare, 0)

    # Update Sudoku to ensure all values have accurate validity.
    puzzleCompleted = puzzle.check_puzzle()

    # update the screen with grid / numbers
    screen.blit(background, (0, 0))
    for r in range(9):
        for c in range(9):
            loc_s = 9 * r + c
            loc_x = squareWidth * c + sum_array(
                spaces[:c + 1]
            )  # calculate the x,y position of the square on screen.
            loc_y = squareWidth * r + sum_array(spaces[:r + 1])

            # Determine the background color:
            sqrColor = lightSquareColor

            # Determine the text color: