Guest User

Untitled

a guest
Dec 10th, 2019
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. class Card:
  2. # Card class fields
  3. CardName = ""
  4. CardNumber = 0
  5. CardSuit = ""
  6.  
  7. # Suit Array
  8. arrCardSuits = ["Diamonds", "Clubs", "Spades", "Hearts"]
  9.  
  10. # Constructor getting only the value and suit number (suits is going to be from 0 o 3)
  11. def __init__(self, value, suit):
  12. # Using other methods to set some of the fields because the data we got from the constructor is not adequate
  13. self.CardNumber = value
  14. self.apply_suit(suit)
  15. self.generate_name(value, self.CardSuit)
  16.  
  17. # Getting the suit name from the array using the index
  18. def apply_suit(self, val):
  19. self.CardSuit = self.arrCardSuits[val]
  20.  
  21. # Making the names so that we don't have to use an array and type them all out
  22. def generate_name(self, val, suit):
  23. if val == 1:
  24. self.CardName = "Ace of " + suit
  25. elif 1 < val < 11:
  26. self.CardName = str(self.CardNumber) + " of " + suit
  27. elif val == 11:
  28. self.CardName = "Jack of " + suit
  29. elif val == 12:
  30. self.CardName = "Queen of " + suit
  31. elif val == 13:
  32. self.CardName = "King of" + suit
  33.  
  34.  
  35. # We are going to store our card here
  36. arrCards = []
  37.  
  38. # Creating the card objects and storing them in the array
  39. for i in range(0, 4):
  40. for j in range(1, 14):
  41. newCard = Card(j, i)
  42. arrCards.append(newCard)
  43.  
  44. # Outputting the names
  45. for i in range(len(arrCards)):
  46. print(arrCards[i].CardName)
Advertisement
Add Comment
Please, Sign In to add comment