import pygame
import random
WIDTH = 500
HEIGHT = 700
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
clock = pygame.time.Clock()
x = 0
x_1 = random.randint(0,9)*50
y_1 = 0
count_obj = 0
while running:
screen.fill(BLACK)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT and x > 0:
x = x - 50
if event.key == pygame.K_RIGHT and x < 450:
x = x + 50
for it_1 in range(0,500,50):
for it_2 in range(0,500,50):
pygame.draw.rect(screen,WHITE, (it_1,it_2,49,49))
pygame.draw.rect(screen,RED, (x_1,y_1,49,49))
y_1 = y_1 + 50
pygame.draw.rect(screen,GREEN, (x,450,49,49))
if (x == x_1 and y_1 == 500):
count_obj = count_obj + 1
img1 = f1.render("Найдено совпадений "+str(count_obj), True, RED)
screen.blit(img1,(0, 550))
if (y_1 == 500):
y_1 = 0
x_1 = random.randint(0,9)*50
pygame.display.update()
clock.tick(5)
pygame.quit()
|