import pygame
import random
import time
pygame.init()
back=(5, 77, 17)
mw=pygame.display.set_mode((500, 500))
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,thicknees):
pygame.draw.rect(mw,frame_color,self.rect,thicknees)
def collidepoint(self, x,y):
return self.rect.collidepoint(x,y)
class Label(Area):
def set_text(self,text,fsize=12, text_color=(168, 17, 17)):
self.image=pygame.font.SysFont('gabriola',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))
cards=list()
num_cards=4
x=70
for i in range(num_cards):
card=Label(x,170,70,100,(255,255,255))
card.outline((0,0,0),6)
card.set_text('CLICK',26)
cards.append(card)
x += 100
wait=0
start_time = time.time()
cur_time=start_time
time_text=Label(0,0,50,50,back)
time_text.set_text('время',40)
timer=Label(50,55,50,40,back)
timer.set_text('0')
time_text.draw(0,0)
while True:
new_time=time.time()
if new_time-cur_time >= 1:
timer.set_text(str(int((new_time - start_time))), 40, (0,0,100))
timer.draw(0,0)
cur_time=new_time
if wait==0:
rnumber=random.randint(0,num_cards)
for i in range(4):
cards[i].color((225,225,225))
if i == rnumber:
cards[i].draw(10,40)
else:
cards[i].fill()
wait=20
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 + 1 == rnumber:
cards[i].color((0,225,0))
print('green')
else:
cards[i].color((225,0,0))
print('red')
cards[i].fill()
pygame.display.update()
clock.tick(40)