Advertisement
Daniel_leinaD

шняга для моих ребят

Feb 4th, 2023
849
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.05 KB | None | 0 0
  1. import pygame
  2. import time
  3. pygame.init()
  4. '''создаём окно программы'''
  5. back = (200, 255, 255) #цвет фона (background)
  6. mw = pygame.display.set_mode((500, 500)) #окно программы (main window)
  7. mw.fill(back)
  8. clock = pygame.time.Clock()
  9. '''класс прямоугольник'''
  10. class Area():
  11.   def __init__(self, x=0, y=0, width=10, height=10, color=None):
  12.       self.rect = pygame.Rect(x, y, width, height) #прямоугольник
  13.       self.fill_color = color
  14.   def color(self, new_color):
  15.       self.fill_color = new_color
  16.   def fill(self):
  17.       pygame.draw.rect(mw, self.fill_color, self.rect)
  18.   def outline(self, frame_color, thickness): #обводка существующего прямоугольника
  19.       pygame.draw.rect(mw, frame_color, self.rect, thickness)  
  20.   def collidepoint(self, x, y):
  21.       return self.rect.collidepoint(x, y)      
  22. '''класс надпись'''
  23. class Label(Area):
  24.   def set_text(self, text, fsize=12, text_color=(0, 0, 0)):
  25.       self.image = pygame.font.SysFont('verdana', fsize).render(text, True, text_color)
  26.   def draw(self, shift_x=0, shift_y=0):
  27.       self.fill()
  28.       mw.blit(self.image, (self.rect.x + shift_x, self.rect.y + shift_y))
  29. RED = (255, 0, 0)
  30. GREEN = (0, 255, 51)
  31. YELLOW = (255, 255, 0)
  32. DARK_BLUE = (0, 0, 100)
  33. BLUE = (80, 80, 255)
  34. cards = []
  35. num_cards = 4
  36. x = 70
  37. for i in range(num_cards):
  38.   new_card = Label(x, 170, 70, 100, YELLOW)
  39.   new_card.outline(BLUE, 10)
  40.   new_card.set_text('CLICK', 26)
  41.   cards.append(new_card)
  42.   x = x + 100
  43.  
  44.  
  45. wait = 0
  46. from random import randint
  47. while True:
  48.   if wait == 0:
  49.       #переносим надпись:
  50.       wait = 20 #столько тиков надпись будет на одном месте
  51.       click = randint(1, num_cards)
  52.       for i in range(num_cards):
  53.           cards[i].color((255,255,0))
  54.           if (i + 1) == click:
  55.               cards[i].draw(10, 40)
  56.           else:
  57.               cards[i].fill()
  58.   else:
  59.       wait -= 1
  60.  
  61.  
  62.   pygame.display.update()
  63.   clock.tick(40)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement