MCPcopy Create free account
hub / github.com/Mrinank-Bhowmick/python-beginner-projects / main

Function main

projects/Sudoku-Solver/SudokuGUI.py:200–312  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

198
199
200def main():
201 screen = pygame.display.set_mode((540, 590))
202 screen.fill((255, 255, 255))
203 pygame.display.set_caption("Sudoku Solver")
204 icon = pygame.image.load("assets/thumbnail.png")
205 pygame.display.set_icon(icon)
206
207 font = pygame.font.SysFont("Bahnschrift", 40)
208 text = font.render("Generating", True, (0, 0, 0))
209 screen.blit(text, (175, 245))
210
211 font = pygame.font.SysFont("Bahnschrift", 40)
212 text = font.render("Random Grid", True, (0, 0, 0))
213 screen.blit(text, (156, 290))
214 pygame.display.flip()
215
216 wrong = 0
217 board = Board(screen)
218 selected = (-1, -1)
219 keyDict = {}
220 running = True
221 startTime = time.time()
222 while running:
223 elapsed = time.time() - startTime
224 passedTime = time.strftime("%H:%M:%S", time.gmtime(elapsed))
225
226 if board.board == board.solvedBoard:
227 for i in range(9):
228 for j in range(9):
229 board.tiles[i][j].selected = False
230 running = False
231
232 for event in pygame.event.get():
233 if event.type == pygame.QUIT:
234 exit()
235 elif event.type == pygame.MOUSEBUTTONUP:
236 mousePos = pygame.mouse.get_pos()
237 for i in range(9):
238 for j in range(9):
239 if board.tiles[i][j].clicked(mousePos):
240 selected = (i, j)
241 board.deselect(board.tiles[i][j])
242 elif event.type == pygame.KEYDOWN:
243 if board.board[selected[1]][selected[0]] == 0 and selected != (-1, -1):
244 if event.key == pygame.K_1:
245 keyDict[selected] = 1
246
247 if event.key == pygame.K_2:
248 keyDict[selected] = 2
249
250 if event.key == pygame.K_3:
251 keyDict[selected] = 3
252
253 if event.key == pygame.K_4:
254 keyDict[selected] = 4
255
256 if event.key == pygame.K_5:
257 keyDict[selected] = 5

Callers 1

SudokuGUI.pyFile · 0.70

Calls 7

deselectMethod · 0.95
hintMethod · 0.95
visualSolveMethod · 0.95
redrawMethod · 0.95
exitFunction · 0.85
clickedMethod · 0.80
BoardClass · 0.70

Tested by

no test coverage detected