Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Card:
- # Card class fields
- CardName = ""
- CardNumber = 0
- CardSuit = ""
- # Suit Array
- arrCardSuits = ["Diamonds", "Clubs", "Spades", "Hearts"]
- # Constructor getting only the value and suit number (suits is going to be from 0 o 3)
- def __init__(self, value, suit):
- # Using other methods to set some of the fields because the data we got from the constructor is not adequate
- self.CardNumber = value
- self.apply_suit(suit)
- self.generate_name(value, self.CardSuit)
- # Getting the suit name from the array using the index
- def apply_suit(self, val):
- self.CardSuit = self.arrCardSuits[val]
- # Making the names so that we don't have to use an array and type them all out
- def generate_name(self, val, suit):
- if val == 1:
- self.CardName = "Ace of " + suit
- elif 1 < val < 11:
- self.CardName = str(self.CardNumber) + " of " + suit
- elif val == 11:
- self.CardName = "Jack of " + suit
- elif val == 12:
- self.CardName = "Queen of " + suit
- elif val == 13:
- self.CardName = "King of" + suit
- # We are going to store our card here
- arrCards = []
- # Creating the card objects and storing them in the array
- for i in range(0, 4):
- for j in range(1, 14):
- newCard = Card(j, i)
- arrCards.append(newCard)
- # Outputting the names
- for i in range(len(arrCards)):
- print(arrCards[i].CardName)
Advertisement
Add Comment
Please, Sign In to add comment