import pygame
import sys
import random
[Link]()
[Link].set_caption('speed match')
# Game settings
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
FPS = 60
BACKGROUND_COLOR = (0, 0, 0)
SHAPE_COLORS = [(255,255,255)]
SHAPES = ['circle', 'square', 'triangle', 'star']
SCORE_POS = (20, 20)
MESSAGE_POS = (SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2)
FONT_SIZE = 30
FONT_COLOR = (255, 255, 255)
wrong_choices=0
# Button settings
BUTTON_WIDTH = 100
BUTTON_HEIGHT = 50
BUTTON_PADDING = 20
BUTTON_COLOR = (255, 255, 255)
BUTTON_HOVER_COLOR = (0, 200, 0)
BUTTON_FONT_SIZE = 24
BUTTON_FONT_COLOR = (0, 0, 0)
CHANCE_POS=(600,20)
screen = [Link].set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
clock = [Link]()
class Shape:
def __init__(self, shape_type, color, position):
self.shape_type = shape_type
[Link] = color
[Link] = position
def draw(self):
if self.shape_type == 'circle':
[Link](screen, 'white', [Link], 50)
[Link](screen,[Link],[Link],40)
elif self.shape_type == 'square':
[Link](screen, [Link],
[Link]([Link][0] - 10, [Link][1] - 10, 10, 10))
[Link](screen, 'white',
[Link]([Link][0] - 40, [Link][1] - 40, 80, 80))
elif self.shape_type == 'triangle':
[Link](screen, [Link], [([Link][0],
[Link][1] - 40),
([Link][0]
- 40, [Link][1] + 40),
([Link][0]
+ 40, [Link][1] + 40)])
elif self.shape_type == 'star':
[Link](screen, [Link], [([Link][0],
[Link][1] + 40),
([Link][0]
+ 40, [Link][1] + 40),
([Link][0]
+ 60, [Link][1] - 60),
([Link][0]
- 40, [Link][1] + 40),
([Link][0]
+ 40, [Link][1] - 40)])
class Button:
def __init__(self, text, position, action):
[Link] = text
[Link] = position
[Link] = action
[Link] = [Link](position[0], position[1], BUTTON_WIDTH,
BUTTON_HEIGHT)
def draw(self):
[Link](screen, BUTTON_COLOR, [Link])
font = [Link](None, BUTTON_FONT_SIZE)
text = [Link]([Link], True, BUTTON_FONT_COLOR)
text_rect = text.get_rect(center=[Link])
[Link](text, text_rect)
def check_collision(self, pos):
return [Link](pos)
def generate_shape():
shape_type = [Link](SHAPES)
color = 'white'
position = (SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2)
return Shape(shape_type, color, position)
def display_score(score):
font = [Link](None, FONT_SIZE)
text = [Link](f"Score: {score}", True, FONT_COLOR)
[Link](text, SCORE_POS)
def display_chances(wrong_choices):
font = [Link](None,FONT_SIZE)
text=[Link](f"Chances Left: {(3-
wrong_choices)}",True,FONT_COLOR)
[Link](text,CHANCE_POS)
def display_message(message):
font = [Link](None, FONT_SIZE)
text = [Link](message, True, FONT_COLOR)
text_rect = text.get_rect(center=MESSAGE_POS)
[Link](text, text_rect)
def StartScreen():
[Link](BACKGROUND_COLOR)
display_message('>Click To Start SpeedMatch')
[Link]()
for event in [Link]():
if [Link]==[Link]:
[Link]()
[Link]()
if [Link] == [Link]:
main_game()
def main_game():
score = 0
wrong_choices = 0
current_shape = generate_shape()
previous_shape = current_shape
buttons = [
Button("Yes", (BUTTON_PADDING, SCREEN_HEIGHT - BUTTON_HEIGHT -
BUTTON_PADDING), "yes"),
Button("No", (BUTTON_PADDING * 2 + BUTTON_WIDTH, SCREEN_HEIGHT
- BUTTON_HEIGHT - BUTTON_PADDING), "no")
]
running = True
while running:
[Link](BACKGROUND_COLOR)
current_shape.draw()
for event in [Link]():
if [Link] == [Link]:
[Link]()
[Link]()
elif [Link] == [Link] and [Link]
== 1:
mouse_pos = [Link].get_pos()
for button in buttons:
if button.check_collision(mouse_pos):
if [Link] == "yes":
if current_shape.shape_type ==
previous_shape.shape_type:
score += 1
wrong_choices += 0
previous_shape=current_shape
current_shape=generate_shape()
else:
wrong_choices += 1
previous_shape=current_shape
current_shape=generate_shape()
elif [Link] == "no":
if current_shape.shape_type !=
previous_shape.shape_type:
score += 1
wrong_choices += 0
previous_shape=current_shape
current_shape=generate_shape()
else:
wrong_choices += 1
previous_shape = current_shape
current_shape=generate_shape()
display_score(score)
display_chances(wrong_choices)
for button in buttons:
[Link]()
if wrong_choices >= 3:
running = False
[Link]()
[Link](FPS)
[Link](BACKGROUND_COLOR)
display_message("Game Over")
[Link]()
[Link](2000)
while True:
StartScreen()