-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsert_board_gui.py
85 lines (79 loc) · 2.87 KB
/
insert_board_gui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import pygame
import time
from my_input_gui import Grid
import suduko_main
background_image = pygame.image.load('game_bg.jpg')
def main():
pygame.font.init()
win = pygame.display.set_mode((600, 700))
pygame.display.set_caption("Sudoku")
b=[[0 for _ in range(9)] for _ in range(9)]
board = Grid(b, 9, 9, 540, 540, win)
key = None
run = True
while run:
#win.fill((255,255,255))
win.blit(background_image, (0, 0))
board.draw()
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_1:
key = 1
if event.key == pygame.K_2:
key = 2
if event.key == pygame.K_3:
key = 3
if event.key == pygame.K_4:
key = 4
if event.key == pygame.K_5:
key = 5
if event.key == pygame.K_6:
key = 6
if event.key == pygame.K_7:
key = 7
if event.key == pygame.K_8:
key = 8
if event.key == pygame.K_9:
key = 9
if event.key == pygame.K_KP1:
key = 1
if event.key == pygame.K_KP2:
key = 2
if event.key == pygame.K_KP3:
key = 3
if event.key == pygame.K_KP4:
key = 4
if event.key == pygame.K_KP5:
key = 5
if event.key == pygame.K_KP6:
key = 6
if event.key == pygame.K_KP7:
key = 7
if event.key == pygame.K_KP8:
key = 8
if event.key == pygame.K_KP9:
key = 9
if event.key == pygame.K_DELETE:
board.clear()
key = None
if event.key == pygame.K_RETURN:
grid_to_solve = board.validate_board()
if grid_to_solve != None:
pygame.quit()
print (grid_to_solve)
suduko_main.main_gui(grid_to_solve)
run = False
#pass array to suduko main
if event.type == pygame.MOUSEBUTTONDOWN:
pos = pygame.mouse.get_pos()
clicked = board.click(pos)
if clicked:
board.select(clicked[0], clicked[1])
key = None
if board.selected and key is not None:
board.sketch(key)
pygame.quit()
#main()