Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Why doesnt the following set card code work? and if i want to import the actual card images where would i put it ? (
Why doesnt the following set card code work? and if i want to import the actual card images where would i put itthe rest of the code is in the screenshot because it won't paste: import pygame
import sys
import random
from enum import Enum
import time
# Define Enums
class NumberEnum:
ONE
TWO
THREE
class SymbolEnum:
DIAMOND 'diamond'
SQUIGGLE 'squiggle'
OVAL 'oval'
class ColorEnum:
RED 'red'
GREEN 'green'
PURPLE 'purple'
class ShadingEnum:
FILLED 'filled'
SHADED 'shaded'
EMPTY 'empty'
# Define SetCard class
class SetCard:
def initself number, symbol, color, shading:
self.number number
self.symbol symbol
self.color color
self.shading shading
def reprself:
return fselfnumber.valueselfsymbol.valueselfcolor.valueselfshading.value
@staticmethod
def issetcard card card:
properties symbol 'color', 'shading', 'number'
return alllensetgetattrcard prop for card in card card card for prop in properties
@staticmethod
def findallsetscards:
n lencards
sets
for i in rangen :
for j in rangei n :
for k in rangej n:
if SetCard.issetcardsi cardsj cardsk:
sets.appendcardsi cardsj cardsk
return sets
# Initialize Pygame
def initpygamedeck:
pygame.init
screen pygame.display.setmode
pygame.display.setcaptionSET Game"
return screen
# Draw text on the screen
def drawtextscreen text, position, fontsize color:
font pygame.font.FontNone fontsize
textsurface font.rendertext True, color
screen.blittextsurface, position
# Draw confetti on the screen
def drawconfettiscreen:
for in range:
x random.randint
y random.randint
pygame.draw.circlescreenx y
# Draw cards on the screen
def drawcardsscreen tablecards:
screen.fill
font pygame.font.FontNone
for i card in enumeratetablecards:
x i
y i
pygame.draw.rectscreenx y
pygame.draw.rectscreenx y
pygame.draw.polygonscreenx y x y x y x y
textcolor if card.color Color.RED else
text font.renderfcardnumber.valuecardsymbol.value True, textcolor
screen.blittextx y
pygame.display.flip
# Draw play button on the screen
def drawplaybuttonscreen:
pygame.draw.rectscreen borderradius
drawtextscreen "Play", fontsize color
# Draw remaining cards on the screen
def drawcardsleftscreen deck:
drawtextscreen fCards Left: lendeck fontsize color
# Reset timer
def resettimer:
return pygame.time.getticks
# Check if play button is clicked
def isplaybuttonclickedx y:
return x and y
# Main game loop
def playsetgame:
# Deck setup
deck SetCardNumbernum Symbolsym Colorcol Shadingshade for num in Number
for sym in Symbol for col in Color for shade in Shading
random.shuffledeck
tablecards deck:
deck deck:
screen initpygamedeck
playerscore
computerscore
computername "Computer"
inactivitytimeout
computerthinkingtime
playbuttonclicked False
while not playbuttonclicked:
for event in pygame.event.get:
if event.type pygame.QUIT:
pygame.quit
sysexit
elif event.type pygame.MOUSEBUTTONDOWN and event.button :
x y event.pos
if isplaybuttonclickedx y:
playbuttonclicked True
drawcardsscreen tablecards
drawplaybuttonscreen
pygame.display.flip
lastactivitytime resettimer
running True
selectedcards
while running and deck:
drawcardsscreen tablecards
drawtextscreen fPlayer Score: playerscore color
drawtextscreen fcomputername Score: computerscore color
drawcardsleftscreen deck
pygame.display.flip
currenttime pygame.time.getticks
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started