import pygame
import random
WIDTH = 500
HEIGHT = 400
FPS = 60
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
f1 = pygame.font.Font(None, 36)
running = True
number = []
for index in range(0,10,1):
number.append(index)
number.append(index)
for index in range(0,20,1):
ind1 = random.randint(0,9)
n1 = number[index]
n2 = number[ind1]
number[index] = n2
number[ind1] = n1
screen.fill(BLACK)
state = []
for index in range(0,20,1):
state.append(1)
print(state)
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
x, y = pygame.mouse.get_pos()
index = 0
if y//100 == 0:
index = 4*(x//100)
if y//100 == 1:
index = 4*(x//100)+1
if y//100 == 2:
index = 4*(x//100)+2
if y//100 == 3:
index = 4*(x//100)+3
state[index] = state[index]+1
print(index)
counter = 0
for it_1 in range(0,500,100):
for it_2 in range(0,400,100):
if (state[counter]==1):
pygame.draw.rect(screen,WHITE, (it_1,it_2,99,99))
font = pygame.font.SysFont(None, 24)
img = font.render(str(number[counter]), True, BLACK)
screen.blit(img, (it_1,it_2))
if (state[counter]==2):
pygame.draw.rect(screen,RED, (it_1,it_2,99,99))
font = pygame.font.SysFont(None, 24)
img = font.render(str(number[counter]), True, BLACK)
screen.blit(img, (it_1,it_2))
if (state[counter]==3):
pygame.draw.rect(screen,GREEN, (it_1,it_2,99,99))
font = pygame.font.SysFont(None, 24)
img = font.render(str(number[counter]), True, BLACK)
screen.blit(img, (it_1,it_2))
counter = counter + 1
pygame.display.update()
pygame.quit()
|