Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import time
- pygame.init()
- from random import randint # IMPORT RANDOM
- '''create programme window'''
- back = (200, 255, 255) #background color
- mw = pygame.display.set_mode((500, 500)) #main window
- mw.fill(back)
- clock = pygame.time.Clock()
- '''rectangle class'''
- class Area():
- def __init__(self, x=0, y=0, width=10, height=10, color=None):
- self.rect = pygame.Rect(x, y, width, height) #rectangle
- 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): #outline of an existing rectangle
- pygame.draw.rect(mw, frame_color, self.rect, thickness)
- '''class label'''
- class Label(Area):
- def set_text(self, text, fsize=12, text_color=(0, 0, 0)):
- self.image = pygame.font.SysFont('comic sans ms', 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))
- YELLOW = (255, 255, 0)
- DARK_BLUE = (0, 0, 100)
- BLUE = (80, 80, 255)
- cards = []
- num_cards = 4
- x = 70
- for i in range(num_cards):
- new_card = Label(x, 200, 70, 100, YELLOW) # x, y, width, height, colour
- new_card.outline(BLUE, 10)
- new_card.set_text('CLICK', 26)
- cards.append(new_card)
- x = x + 100 # Spacing between each card
- while True:
- click = randint(1, num_cards) # UPDATE THIS SECTION
- for i in range(num_cards):
- cards[i].color(YELLOW)
- if (i + 1) == click:
- cards[i].draw(10, 40) # SHOW THE WORD CLICK
- else:
- cards[i].fill() # TURN THE CARD YELLOW (BLANK)
- pygame.display.update() # KEEP THESE TWO LINES
- clock.tick(40)
Add Comment
Please, Sign In to add comment