External Exam Download Resources Web Applications Games Recycle Bin

Choose between two cards

choose a card.py

import pygame
pygame.init()
screen = pygame.display.set_mode((400, 300))
done = False
ace = pygame.image.load("as.gif")
two = pygame.image.load("2h.gif")

while not done:
  screen.blit(ace, (50, 50))
  screen.blit(two, (250, 50))
  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      done = True
    if event.type == pygame.MOUSEBUTTONDOWN:
      x, y = event.pos #alternative to pygame.mouse.get_pos()
      if ace.get_rect(topleft=(50,50)).collidepoint(x,y):
        print("you clicked on the ace")
      if two.get_rect(topleft=(250,50)).collidepoint(x,y):
        print("you clicked on the two")  
  
  pygame.display.flip()
  
pygame.quit()


put image files + python file into same folder: