External Exam Download Resources Web Applications Games Recycle Bin

Cups guessing game randomized

cups guessing game randomized.py

import pygame,random
pygame.init()
screen = pygame.display.set_mode((400, 300))
done = False

cup1 = pygame.image.load("cup.png")
cup2 = pygame.image.load("cup.png")
cup3 = pygame.image.load("cup.png")

ball = random.randint(1,3)

while not done:
  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      done = True
    if event.type == pygame.MOUSEBUTTONDOWN:
      click = pygame.mouse.get_pos()
      
      if cup1.get_rect(topleft=(0,50)).collidepoint(click):
        if ball == 1:
          cup1 = pygame.image.load("cup_and_ball.png")
        else:
          cup1 = pygame.image.load("cup_and_nothing.png")
      
      if cup2.get_rect(topleft=(150,50)).collidepoint(click):
        if ball == 2:
          cup2 = pygame.image.load("cup_and_ball.png")
        else:
          cup2 = pygame.image.load("cup_and_nothing.png")
          
      if cup3.get_rect(topleft=(300,50)).collidepoint(click):
        if ball == 3:
          cup3 = pygame.image.load("cup_and_ball.png")
        else:
          cup3 = pygame.image.load("cup_and_nothing.png")
          
  screen.blit(cup1, (0, 50))
  screen.blit(cup2, (150, 50))
  screen.blit(cup3, (300, 50))
  pygame.display.flip()
  
pygame.quit()
     
put all images and python file into same folder: