import pygame
import random
WIDTH = 500
HEIGHT = 500
PS = 5
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))
clock = pygame.time.Clock()
pygame.time.set_timer(pygame.USEREVENT, 1000)
running = True
X = 150
Y = 200
while running:
screen.fill(BLACK)
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))
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.USEREVENT:
select = random.randint(0,5)
if select == 0:
pygame.draw.rect(screen,RED, (X,Y,49,49))
pygame.draw.rect(screen,RED, (X+50,Y,49,49))
pygame.draw.rect(screen,RED, (X+100,Y,49,49))
pygame.draw.rect(screen,RED, (X+50,Y+50,49,49))
if select == 1:
pygame.draw.rect(screen,RED, (X+100,Y,49,49))
pygame.draw.rect(screen,RED, (X+150,Y,49,49))
pygame.draw.rect(screen,RED, (X+50,Y+50,49,49))
pygame.draw.rect(screen,RED, (X+100,Y+50,49,49))
if select == 2:
pygame.draw.rect(screen,RED, (X,Y,49,49))
pygame.draw.rect(screen,RED, (X+50,Y,49,49))
pygame.draw.rect(screen,RED, (X+50,Y+50,49,49))
pygame.draw.rect(screen,RED, (X+100,Y+50,49,49))
if select == 3:
pygame.draw.rect(screen,RED, (X+50,Y,49,49))
pygame.draw.rect(screen,RED, (X+50,Y-50,49,49))
pygame.draw.rect(screen,RED, (X+50,Y+50,49,49))
pygame.draw.rect(screen,RED, (X+50,Y+100,49,49))
if select == 4:
pygame.draw.rect(screen,RED, (X+50,Y,49,49))
pygame.draw.rect(screen,RED, (X+50,Y-50,49,49))
pygame.draw.rect(screen,RED, (X+50,Y+50,49,49))
pygame.draw.rect(screen,RED, (X,Y+50,49,49))
if select == 5:
pygame.draw.rect(screen,RED, (X+50,Y,49,49))
pygame.draw.rect(screen,RED, (X+50,Y-50,49,49))
pygame.draw.rect(screen,RED, (X+50,Y+50,49,49))
pygame.draw.rect(screen,RED, (X+100,Y+50,49,49))
pygame.display.flip()
pygame.quit()
|