Загрузка данных


import pygame
import time
from random import *
 
 
pygame.init()
 
 
 
 
"""создаём окно программы"""
 
 
 
 
back = (200, 255, 255)  # цвет фона (background)
mw = pygame.display.set_mode((500, 500))  # окно программы (main window)
mw.fill(back)
clock = pygame.time.Clock()
 
 
 
 
"""класс прямоугольник"""
 
 
 
 
class Area:
    def __init__(self, x=0, y=0, width=10, height=10, color=None):
        self.rect = pygame.Rect(x, y, width, height)  # прямоугольник
        self.fill_color = color
 
 
    def color(self, new_color):
        self.fill_color = new_color
 
 
    def fill(self):
        pygame.draw.rect(mw, self.fill_color, self.rect)
 
 
    def outline(
        self, frame_color, thickness
    ):  # обводка существующего прямоугольника
        pygame.draw.rect(mw, frame_color, self.rect, thickness)
 
 
 
 
"""класс надпись"""
 
 
 
 
class Label(Area):
    def set_text(self, text, fsize=12, text_color=(0, 0, 0)):
        self.image = pygame.font.SysFont("verdana", fsize).render(
            text, True, text_color
        )
 
 
    def draw(self, shift_x=0, shift_y=0):
        self.fill()
        mw.blit(self.image, (self.rect.x + shift_x, self.rect.y + shift_y))
    def collidepoint(self, x, y):
        return self.rect.collidepoint(x, y)
 
 
 
YELLOW = (255, 255, 0)
DARK_BLUE = (0, 0, 100)
BLUE = (80, 80, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 51)
BlUE = (0, 0, 255)
ORANGE = (255, 123, 0)
WHITE = (255, 255, 255)
YELLOW = (255, 255, 0)
LIGHT_GREEN = (200, 255, 200)
LIGHT_RED = (250, 128, 114)
BLACK = (0, 0, 0)
DARK_BLUE = (0, 0, 100)
LIGHT_BLUE = (80, 80, 255)
cards = []
num_cards = 4

x = 70
 
for i in range(num_cards):
    new_card = Label(x, 100, 70, 100, YELLOW)
    new_card.outline(BLUE, 10)
    new_card.set_text("CLICK", 26)
    cards.append(new_card)
    x = x + 100
 
x,y=0,0
wait = 0
while True:
    for event in pygame.event.get():
        if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
            x, y = event.pos
            for i in range(num_cards):
                if cards[i].collidepoint(x,y):
                    if i== number: 
                        cards[i].color(GREEN)
                    else: 
                        cards[i].color(RED)
                    cards[i].fill()
    if wait == 0:
        number = randint(0, 3)
        for i in range(4):
            cards[i].color(YELLOW)
            if i == number:
                cards[i].set_text("CLICK", 24)
                cards[i].draw(10, 30)
            else:
                cards[i].fill()
        wait = 20
    else:
        wait -= 1
    pygame.display.update()
    clock.tick(40)