Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pprint import pprint
- import pygame
- class GamePiece:
- def __init__(self):
- self.checked = False
- def is_clicked(self):
- return self.checked
- def set_clicked(self):
- self.checked = True
- def set_unclicked(self):
- self.checked = False
- board = [[GamePiece() for _ in range(0, 9)] for _ in range(0, 12)]
- def main():
- pygame.init()
- surface_size = 33
- main_surface = pygame.display.set_mode(
- (surface_size * 9, surface_size * 12))
- pos = (300, 200)
- some_color = (255, 0, 0)
- clicked = False
- pprint(board)
- while True:
- event = pygame.event.poll()
- if event.type == pygame.QUIT:
- break
- if event.type == pygame.MOUSEBUTTONDOWN:
- global pos, clicked
- p = pygame.mouse.get_pos()
- index_x = p[0] / 33
- index_y = p[1] / 33
- cc = board[index_x][index_y]
- if cc.is_clicked():
- print('yeah')
- board[index_x][index_y].set_unclicked()
- else:
- cc.set_clicked()
- print('now set')
- # else:
- # if (p[0] > pos[0] and p[0] < pos[0] + 33) and (p[1] > pos[1] and p[1] < pos[1] + 33):
- # ]
- # clicked = True
- # else:
- # pass
- main_surface.fill((0, 200, 255))
- small_rect = (pos[0], pos[1], 33, 33)
- main_surface.fill(some_color, small_rect)
- pygame.display.flip()
- pygame.quit()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement