Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # name-Alex.G
- # class-ICS2O
- # assignment- 52 cards
- # due date- December 19, 2018
- #discription- This program output 52 cards at random when the user requests one, and stops if they chose not to or if they have drawn 52 cards
- import pygame, time
- # initialize the pygame code
- pygame.init()
- #window size
- surface = pygame.display.set_mode([1000,500])
- import random
- # -----------------------------
- #background
- color = pygame.Color("black")
- surface.fill(color)
- #variables
- draw = "y"
- cards = 0
- #defining symbols
- def sym (suit, y):
- #colour for symbols
- color1 = pygame.Color("black")
- color2 = pygame.Color("red")
- if suit == 1:
- #square
- rect=pygame.Rect(490,110+y,15,15)
- pygame.draw.rect(surface, color1, rect)
- elif suit == 2:
- #circle
- pygame.draw.circle(surface, color1, [500,120+y], 8)
- elif suit == 3:
- #diamond
- pygame.draw.polygon(surface, color2, [[500,110+y], [490,115+y], [500,120+y] ,[510,115+y]], 0)
- else:
- #triangle
- pygame.draw.polygon(surface, color2, [[500,110+y], [490,120+y], [510,120+y]], 0)
- #store cards drawn
- list = []
- #explain program to user
- print ("This is a program to draw random cards for a 52 card deck")
- #loop if user draws card
- while draw == "y":
- pygame.event.get()
- #ask user if they wish to draw a card
- draw = input("Do you wish to draw a card, y, or n - ")
- pygame.display.flip()
- #end loop if 52 cards are drawn
- if cards == 52:
- #let user know they have reached the max amout of cards
- print ("You have reached the max amount of cards")
- break
- #if card gets drawn
- if draw == "y":
- #get random number between 1 and 13
- n = random.randint (1,13)
- #convert number to string
- n2 = str(n)
- #get random number between 1 and 4
- suit = random.randint (1,4)
- #convert to string
- suit2 = str(suit)
- #add two string numbers together
- add = (n2+suit2)
- #if add is already in the list of cards drawn do loop
- while add in list:
- #get random number between 1 and 13
- n = random.randint (1,13)
- #convert number to string
- n2 = str(n)
- #get random number between 1 and 4
- suit = random.randint (1,4)
- #convert to string
- suit2 = str(suit)
- #add two string numbers together
- add = (n2+suit2)
- #put add in the list of cards drawn
- list.append(add)
- print (list)
- #output outline of card, and put of the old one
- color1 = pygame.Color("black")
- color2 = pygame.Color("white")
- rect1=pygame.Rect(425,100,150,300)
- pygame.draw.rect(surface, color2, rect1)
- #while z is between 0 and n do loop
- for z in range(0,n):
- #do z multiplied by 23
- y = z * 22
- #output symbol
- sym(suit, y)
- #add 1 to card counter
- cards = cards + 1
- #get font and font size for numbers
- myfont = pygame.font.SysFont("Times", 30)
- #the number is the random number
- number = myfont.render(n2, 1, color1)
- #output numbers at top left and bottom right of card
- surface.blit(number, (435, 110))
- surface.blit(number, (540, 360))
- pygame.display.flip()
- #user friendly ending
- print ("Thanks for playing")
- #quit game
- pygame.display.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement