shh_algo_PY

Fast Clicker Interface - July 9th

Jul 9th, 2022 (edited)
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.88 KB | None | 0 0
  1. import pygame
  2. import time
  3. pygame.init()
  4.  
  5. from random import randint      # IMPORT RANDOM
  6.  
  7. '''create programme window'''
  8.  
  9. back = (200, 255, 255) #background color
  10. mw = pygame.display.set_mode((500, 500)) #main window
  11. mw.fill(back)
  12. clock = pygame.time.Clock()
  13.  
  14. '''rectangle class'''
  15.  
  16. class Area():
  17.     def __init__(self, x=0, y=0, width=10, height=10, color=None):
  18.         self.rect = pygame.Rect(x, y, width, height) #rectangle
  19.         self.fill_color = color
  20.  
  21.     def color(self, new_color):
  22.         self.fill_color = new_color
  23.  
  24.     def fill(self):
  25.         pygame.draw.rect(mw, self.fill_color, self.rect)
  26.  
  27.     def outline(self, frame_color, thickness): #outline of an existing rectangle
  28.         pygame.draw.rect(mw, frame_color, self.rect, thickness)    
  29.  
  30.  
  31. '''class label'''
  32.  
  33. class Label(Area):
  34.     def set_text(self, text, fsize=12, text_color=(0, 0, 0)):
  35.         self.image = pygame.font.SysFont('comic sans ms', fsize).render(text, True, text_color)
  36.  
  37.     def draw(self, shift_x=0, shift_y=0):
  38.         self.fill()
  39.         mw.blit(self.image, (self.rect.x + shift_x, self.rect.y + shift_y))
  40.  
  41. YELLOW = (255, 255, 0)
  42. DARK_BLUE = (0, 0, 100)
  43. BLUE = (80, 80, 255)
  44.  
  45. cards = []
  46. num_cards = 4
  47.  
  48. x = 70
  49.  
  50. for i in range(num_cards):
  51.     new_card = Label(x, 200, 70, 100, YELLOW) # x, y, width, height, colour
  52.     new_card.outline(BLUE, 10)
  53.     new_card.set_text('CLICK', 26)
  54.     cards.append(new_card)
  55.     x = x + 100 # Spacing between each card
  56.  
  57. while True:
  58.     click = randint(1, num_cards)       # UPDATE THIS SECTION
  59.     for i in range(num_cards):
  60.         cards[i].color(YELLOW)
  61.         if (i + 1) == click:
  62.             cards[i].draw(10, 40)      # SHOW THE WORD CLICK
  63.         else:
  64.             cards[i].fill()            # TURN THE CARD YELLOW (BLANK)
  65.  
  66.     pygame.display.update()         # KEEP THESE TWO LINES
  67.     clock.tick(40)                
  68.  
  69.  
Add Comment
Please, Sign In to add comment