Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have the following code for a SET game and I cant get the images to visualize it to work, every time i put the

I have the following code for a SET game and I cant get the images to visualize it to work, every time i put the images in the only thing i get is an empty black window when I run the game: import pygame
import sys
import random
import threading
import queue
import time
from enum import Enum
# Enum definitions
class Number(Enum):
ONE =1
TWO =2
THREE =3
class Symbol(Enum):
DIAMOND = 'diamond'
SQUIGGLE = 'squiggle'
OVAL = 'oval'
class Color(Enum):
RED = 'red'
GREEN = 'green'
PURPLE = 'purple'
class Shading(Enum):
SOLID = 'solid'
STRIPED = 'striped'
OPEN = 'open'
# SetCard class
class SetCard:
def __init__(self, number, symbol, color, shading):
self.number = number
self.symbol = symbol
self.color = color
self.shading = shading
def __repr__(self):
return f'Number: {self.number.value}, Symbol: {self.symbol.value}, Color: {self.color.value}, Shading: {self.shading.value}'
@staticmethod
def is_set(card1, card2, card3):
properties =['number', 'symbol', 'color', 'shading']
for prop in properties:
if len(set([getattr(card1, prop), getattr(card2, prop), getattr(card3, prop)]))!=2:
return False
return True
@staticmethod
def find_all_sets(cards):
n = len(cards)
sets =[]
for i in range(n-2):
for j in range(i+1, n-1):
for k in range(j+1, n):
if SetCard.is_set(cards[i], cards[j], cards[k]):
sets.append((cards[i], cards[j], cards[k]))
return sets
# Function to initialize Pygame and load card images
def init_pygame(deck):
pygame.init()
screen = pygame.display.set_mode((800,600))
pygame.display.set_caption("SET Game")
card_images ={}
for card in deck:
# Replace with actual image loading logic
card_images[card]= pygame.Surface((100,150)) # Placeholder for card images
card_images[card].fill((255,255,255)) # White cards for now
return screen, card_images
# Function to draw cards on the screen
def draw_cards(screen, table_cards, card_images):
screen.fill((0,0,0)) # Black background
for i, card in enumerate(table_cards):
x =50+(i %3)*150
y =50+(i //3)*200
screen.blit(card_images[card],(x, y))
# Main game function
def play_set_game():
deck =[SetCard(Number(num), Symbol(sym), Color(col), Shading(shade))
for num in Number for sym in Symbol for col in Color for shade in Shading]
random.shuffle(deck)
table_cards = deck[:12]
deck = deck[12:]
screen, card_images = init_pygame(deck)
# Game loop
running = True
while running and deck:
draw_cards(screen, table_cards, card_images)
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Add more event handling as needed
pygame.quit()
if __name__=="__main__":
play_set_game() I copied the path to the images : ""C:\Users\Gebruiker\OneDrive - HvA\Desktop\cards\purplesquiggleshaded3.gif"
"C:\Users\Gebruiker\OneDrive - HvA\Desktop\cards\reddiamondempty1.gif"
"C:\Users\Gebruiker\OneDrive - HvA\Desktop\cards\reddiamondempty2.gif"
"C:\Users\Gebruiker\OneDrive - HvA\Desktop\cards\reddiamondempty3.gif"
"C:\Users\Gebruiker\OneDrive - HvA\Desktop\cards\reddiamondfilled1.gif"
"C:\Users\Gebruiker\OneDrive - HvA\Desktop\cards\reddiamondfilled2.gif"
"C:\Users\Gebruiker\OneDrive - HvA\Desktop\cards\reddiamondfilled3.gif"
"C:\Users\Gebruiker\OneDrive - HvA\Desktop\cards\reddiamondshaded1.gif"
"C:\Users\Gebruiker\OneDrive - HvA\Desktop\cards\reddiamondshaded2.gif"
"C:\Users\Gebruiker\OneDrive - HvA\Desktop\cards\reddiamondshaded3.gif"
"C:\Users\Gebruiker\OneDrive - HvA\Desktop\cards\redovalempty1.gif"
"C:\Users\Gebruiker\OneDrive - HvA\Desktop\cards\redovalempty2.gif"
"C:\Users\Gebruiker\OneDrive - HvA\Desktop\cards\redovalempty3.gif"
"C:\Users\Gebruiker\OneDrive - HvA\Desktop\cards\redovalfilled1.gif"
"C:\Users\Gebruiker\OneDrive - HvA\Desktop\cards\redovalfilled2.gif"
"C:\Users\Gebruiker\OneDrive - HvA\Desktop\cards\redovalfilled3.gif"
"C:\Users\Gebruiker\OneDrive - HvA\Desktop\cards\redovalshaded1.gif"
"C:\Users\Gebruiker\OneDrive - HvA\Desktop\cards\redovalshaded2.gif"
"C:\Users\Gebruiker\OneDrive - HvA\Desktop\cards\redovalshaded3.gif"
"C:\Users\Gebruiker\OneDrive - HvA\Desktop\cards\redsquiggleempty1.gif"
"C:\Users\Gebruiker\OneDrive - HvA\Desktop\cards\redsquiggleempty2.gif"
"C:\Users\Gebruiker\OneDrive - HvA\Desktop\cards\redsquiggleempty3.gif"
"C:\Users\Gebruiker\OneDrive - HvA\Desktop\cards\redsquigglefilled1.gif""

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions