import pygame
import random
WIDTH = 500
HEIGHT = 700
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
x = 0
y = 100
x1 = random.randint(0,10)*50
y1 = random.randint(1,11)*50+100
state = 1
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:
x = x - 50
if event.key == pygame.K_RIGHT:
x = x + 50
if event.key == pygame.K_DOWN:
y = y + 50
if event.key == pygame.K_UP:
y = y - 50
if event.key == pygame.K_RETURN:
state = 3
for it_1 in range(0,500,50):
for it_2 in range(0,700,50):
pygame.draw.rect(screen,WHITE, (it_1,it_2+100,49,49))
if (x < 0): x = 0
if (x > 450): x = 450
if (y > 650): y = 650
if (y < 100): y = 100
if (state == 1 or state == 3):
ticks=pygame.time.get_ticks()
img = f1.render("Прошло секунд "+str(ticks//1000), True, RED)
screen.blit(img, (0, 0))
if (x == x1 and y == y1 ):
state = 2
img2 = f1.render("Совпадение найдено ", True, RED)
screen.blit(img2,(0, 50))
if (state == 3):
pygame.draw.rect(screen,RED, (x1,y1,49,49))
pygame.draw.rect(screen,GREEN, (x,y,49,49))
pygame.display.update()
pygame.quit()
|