PySudoku.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import sys, os, random, pygame
  2. sys.path.append(os.path.join("objects"))
  3. import SudokuSquare
  4. from GameResources import *
  5. digits = '123456789'
  6. rows = 'ABCDEFGHI'
  7. def play(values_list):
  8. pygame.init()
  9. size = width, height = 700, 700
  10. screen = pygame.display.set_mode(size)
  11. background_image = pygame.image.load("./images/sudoku-board-bare.jpg").convert()
  12. clock = pygame.time.Clock()
  13. # The puzzleNumber sets a seed so either generate
  14. # a random number to fill in here or accept user
  15. # input for a duplicatable puzzle.
  16. for values in values_list:
  17. pygame.event.pump()
  18. theSquares = []
  19. initXLoc = 0
  20. initYLoc = 0
  21. startX, startY, editable, number = 0, 0, "N", 0
  22. for y in range(9):
  23. for x in range(9):
  24. if x in (0, 1, 2): startX = (x * 57) + 38
  25. if x in (3, 4, 5): startX = (x * 57) + 99
  26. if x in (6, 7, 8): startX = (x * 57) + 159
  27. if y in (0, 1, 2): startY = (y * 57) + 35
  28. if y in (3, 4, 5): startY = (y * 57) + 100
  29. if y in (6, 7, 8): startY = (y * 57) + 165
  30. col = digits[x]
  31. row = rows[y]
  32. string_number = values[row + col]
  33. if len(string_number) > 1 or string_number == '' or string_number == '.':
  34. number = None
  35. else:
  36. number = int(string_number)
  37. theSquares.append(SudokuSquare.SudokuSquare(number, startX, startY, editable, x, y))
  38. screen.blit(background_image, (0, 0))
  39. for num in theSquares:
  40. num.draw()
  41. pygame.display.flip()
  42. pygame.display.update()
  43. clock.tick(5)
  44. # leave game showing until closed by user
  45. while True:
  46. for event in pygame.event.get():
  47. if event.type == pygame.QUIT:
  48. pygame.quit()
  49. quit()
  50. if __name__ == "__main__":
  51. main()
  52. sys.exit()