Untitled
unknown
plain_text
10 months ago
2.6 kB
21
Indexable
import pygame
from random import randint
pygame.init()
back = (200, 255, 255) #RGB
mw = pygame.display.set_mode((500, 500))
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)
#
clock = pygame.time.Clock()
class Area():
def __init__(self, x, y, width, height, new_color):
self.rect = pygame.Rect( x, y, width, height)
self.fill_color = new_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 = DARK_BLUE, thickness = 5):
pygame.draw.rect(mw, frame_color, self.rect, thickness )
def collidepoint(self, x, y):
return self.rect.collidepoint(x, y)
class Label(Area):
def set_text(self, text, fsize = 40, text_color = (0, 0, 0)):
self.image = pygame.font.SysFont("Impact", fsize).render(text, True, text_color)
def draw(self, shift_x, shift_y):
self.fill()
mw.blit(self.image, (self.rect.x + shift_x, self.rect.y+ shift_y))
CARD_WIDTH = 70
CARD_HEIGHT = 100
cards = []
num_cards = 3
x = 70
mw.fill(back)
#починаємо заповнення списку карток
for i in range (num_cards):
card = Label(x, 180, CARD_WIDTH, CARD_HEIGHT, YELLOW)
card.set_text("click")
card.outline()
cards.append(card)
x = x + CARD_WIDTH + 15
wait = 0
while True:
if wait == 0:
wait = 70
click = randint(0, num_cards - 1)
for i in range (num_cards):
cards[i].color(YELLOW)
if i == click:
cards[i].draw(15,40)
else:
cards[i].fill()
else:
wait -= 1
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 == click:
cards[i].color(GREEN)
else:
cards[i].color(RED)
cards[i].fill()
if i == click:
cards[i].draw(15,40)
pygame.display.update()
clock.tick(60)
Editor is loading...
Leave a Comment