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
counter = 0
numbers = []
x = 0
y = 0
numbers.append(random.randint(0,25))
def is_elem(r):
for i in range(0,len(numbers)):
if r == numbers[i]: return 1
return 2
def randomnumber():
wexit = 1
while wexit == 1:
r = random.randint(0,25)
if is_elem(r) == 2:
numbers.append(r)
if (len(numbers) == 20):
wexit = 0
randomnumber()
while 1:
r = random.randint(0,25)
if is_elem(r) == 2:
index1 = random.randint(0,19)
index2 = random.randint(0,19)
if index1 != index2:
numbers[index1] = r
numbers[index2] = r
break
while running:
screen.fill(BLACK)
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()
x = x//100 * 100
y = y//100 * 100
ipos = 0
if y//100 == 0:
ipos = 4*(x//100)
if y//100 == 1:
ipos = 4*(x//100)+1
if y//100 == 2:
ipos = 4*(x//100)+2
if y//100 == 3:
ipos = 4*(x//100)+3
numbers[ipos] += 1
counter = 0
for it_1 in range(0,500,100):
for it_2 in range(0,400,100):
pygame.draw.rect(screen,WHITE, (it_1,it_2,99,99))
font = pygame.font.SysFont(None, 34)
if (index1 == counter): pygame.draw.rect(screen,GREEN, (it_1,it_2,99,99))
img = font.render(str(numbers[counter]), True, BLACK)
screen.blit(img, (it_1,it_2))
counter = counter + 1
pygame.display.update()
pygame.quit()
|