Advertisement
Guest User

1212

a guest
Dec 19th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. # name-Alex.G
  2. # class-ICS2O
  3. # assignment- 52 cards
  4. # due date- December 19, 2018
  5. #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
  6.  
  7. import pygame, time
  8. # initialize the pygame code
  9. pygame.init()
  10.  
  11. #window size
  12. surface = pygame.display.set_mode([1000,500])
  13.  
  14. import random
  15.  
  16. # -----------------------------
  17. #background
  18. color = pygame.Color("black")
  19. surface.fill(color)
  20.  
  21. #variables
  22. draw = "y"
  23. cards = 0
  24.  
  25. #defining symbols
  26. def sym (suit, y):
  27.  
  28. #colour for symbols
  29. color1 = pygame.Color("black")
  30. color2 = pygame.Color("red")
  31.  
  32. if suit == 1:
  33.  
  34. #square
  35. rect=pygame.Rect(490,110+y,15,15)
  36. pygame.draw.rect(surface, color1, rect)
  37.  
  38. elif suit == 2:
  39.  
  40. #circle
  41. pygame.draw.circle(surface, color1, [500,120+y], 8)
  42.  
  43. elif suit == 3:
  44.  
  45. #diamond
  46. pygame.draw.polygon(surface, color2, [[500,110+y], [490,115+y], [500,120+y] ,[510,115+y]], 0)
  47.  
  48. else:
  49.  
  50. #triangle
  51. pygame.draw.polygon(surface, color2, [[500,110+y], [490,120+y], [510,120+y]], 0)
  52.  
  53. #store cards drawn
  54. list = []
  55.  
  56. #explain program to user
  57. print ("This is a program to draw random cards for a 52 card deck")
  58.  
  59.  
  60. #loop if user draws card
  61. while draw == "y":
  62. pygame.event.get()
  63. #ask user if they wish to draw a card
  64. draw = input("Do you wish to draw a card, y, or n - ")
  65.  
  66. pygame.display.flip()
  67. #end loop if 52 cards are drawn
  68. if cards == 52:
  69. #let user know they have reached the max amout of cards
  70. print ("You have reached the max amount of cards")
  71. break
  72.  
  73. #if card gets drawn
  74. if draw == "y":
  75.  
  76. #get random number between 1 and 13
  77.  
  78. n = random.randint (1,13)
  79. #convert number to string
  80. n2 = str(n)
  81.  
  82. #get random number between 1 and 4
  83. suit = random.randint (1,4)
  84. #convert to string
  85. suit2 = str(suit)
  86.  
  87. #add two string numbers together
  88. add = (n2+suit2)
  89.  
  90. #if add is already in the list of cards drawn do loop
  91. while add in list:
  92.  
  93. #get random number between 1 and 13
  94.  
  95. n = random.randint (1,13)
  96. #convert number to string
  97. n2 = str(n)
  98.  
  99. #get random number between 1 and 4
  100. suit = random.randint (1,4)
  101. #convert to string
  102. suit2 = str(suit)
  103. #add two string numbers together
  104. add = (n2+suit2)
  105.  
  106. #put add in the list of cards drawn
  107. list.append(add)
  108.  
  109. print (list)
  110.  
  111. #output outline of card, and put of the old one
  112. color1 = pygame.Color("black")
  113. color2 = pygame.Color("white")
  114. rect1=pygame.Rect(425,100,150,300)
  115. pygame.draw.rect(surface, color2, rect1)
  116.  
  117. #while z is between 0 and n do loop
  118. for z in range(0,n):
  119.  
  120. #do z multiplied by 23
  121. y = z * 22
  122.  
  123. #output symbol
  124. sym(suit, y)
  125.  
  126. #add 1 to card counter
  127. cards = cards + 1
  128.  
  129. #get font and font size for numbers
  130. myfont = pygame.font.SysFont("Times", 30)
  131.  
  132. #the number is the random number
  133. number = myfont.render(n2, 1, color1)
  134.  
  135. #output numbers at top left and bottom right of card
  136. surface.blit(number, (435, 110))
  137. surface.blit(number, (540, 360))
  138.  
  139. pygame.display.flip()
  140.  
  141. #user friendly ending
  142. print ("Thanks for playing")
  143.  
  144. #quit game
  145. pygame.display.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement