Hi,
I'm learning python and I just started to learn about classes. To get a handle on this, I decided to make a black jack game and create 3 classes: deck, hand, and card. I created a card class, but I am not sure how I would implement it in the hand class when I create those methods.
For example, did I do the add_card method correctly for the hand class? How does python know that card must be of class Card?
Thank you!
SUITS = ('C', 'S', 'H', 'D')
RANKS = ('A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K')
VALUES = { 'A':1, '2':2, '3':3, '4':4, '5':5, '6':6,
'7':7, '8':8, '9':9, 'T':10, 'J':10, 'Q':10, 'K':10
}
# define card class
class Card:
def __init__(self, suit, rank):
if (suit in SUITS) and (rank in RANKS):
self.suit = suit
self.rank = rank
else:
self.suit = None
self.rank = None
print "Invalid card: ", suit, rank
def __str__(self):
return self.suit + self.rank
def get_suit(self):
return self.suit
def get_rank(self):
return self.rank
# define hand class
class Hand:
def __init__(self):
self.hand = []
def __str__(self):
return self.hand
def add_card(self, card):
return self.hand.append(card)
# count aces as 1, if the hand has an ace, then add 10 to hand value if it doesn't bust
def get_value(self):
def busted(self):
pass
def draw(self, canvas, p):
pass
# define deck class
class Deck:
def __init__(self):
self.
# add cards back to deck and shuffle
def shuffle(self):
pass
def deal_card(self):
pass
def __str__(self):
pass