Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2015
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. from pprint import pprint
  2.  
  3. import pygame
  4.  
  5.  
  6. class GamePiece:
  7.  
  8. def __init__(self):
  9. self.checked = False
  10.  
  11. def is_clicked(self):
  12. return self.checked
  13.  
  14. def set_clicked(self):
  15. self.checked = True
  16.  
  17. def set_unclicked(self):
  18. self.checked = False
  19.  
  20.  
  21. board = [[GamePiece() for _ in range(0, 9)] for _ in range(0, 12)]
  22.  
  23.  
  24. def main():
  25. pygame.init()
  26. surface_size = 33
  27.  
  28. main_surface = pygame.display.set_mode(
  29. (surface_size * 9, surface_size * 12))
  30.  
  31. pos = (300, 200)
  32.  
  33. some_color = (255, 0, 0)
  34.  
  35. clicked = False
  36. pprint(board)
  37.  
  38. while True:
  39. event = pygame.event.poll()
  40. if event.type == pygame.QUIT:
  41. break
  42. if event.type == pygame.MOUSEBUTTONDOWN:
  43. global pos, clicked
  44. p = pygame.mouse.get_pos()
  45.  
  46. index_x = p[0] / 33
  47. index_y = p[1] / 33
  48. cc = board[index_x][index_y]
  49.  
  50. if cc.is_clicked():
  51. print('yeah')
  52. board[index_x][index_y].set_unclicked()
  53. else:
  54. cc.set_clicked()
  55. print('now set')
  56.  
  57. # else:
  58. # if (p[0] > pos[0] and p[0] < pos[0] + 33) and (p[1] > pos[1] and p[1] < pos[1] + 33):
  59. # ]
  60. # clicked = True
  61. # else:
  62. # pass
  63.  
  64. main_surface.fill((0, 200, 255))
  65. small_rect = (pos[0], pos[1], 33, 33)
  66. main_surface.fill(some_color, small_rect)
  67.  
  68. pygame.display.flip()
  69.  
  70. pygame.quit()
  71.  
  72. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement