Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SUITS=('S','D','C','H')
- RANKS=('A',2,3,4,5,6,7,8,9,10,'J','Q','K')
- # 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 "%s%s" % (self.suit, self.rank)
- def get_suit(self):
- return self.suit
- def get_rank(self):
- return self.rank
- # def draw(self, canvas, pos):
- # card_loc = (CARD_CENTER[0] + CARD_SIZE[0] * RANKS.index(self.rank),
- # CARD_CENTER[1] + CARD_SIZE[1] * SUITS.index(self.suit))
- # canvas.draw_image(card_images, card_loc, CARD_SIZE, [pos[0] + CARD_CENTER[0], pos[1] + CARD_CENTER[1]], CARD_SIZE)
- # define hand class
- class Hand:
- def __init__(self):
- self.hand =[]
- # create Hand object
- def __str__(self):
- s = None
- for card in self.hand:
- print "# adding %s" % str(card)
- if s:
- s = s + "," + str(card)
- else:
- s = str(card)
- return s
- def add_card(self, card):
- print "Adding card %s" % card
- self.hand.append(card)
- # add a card object to a hand
- def get_value(self):
- pass
- #aceval = 1
- #self.val1 = 0
- # count aces as 1, if the hand has an ace, then add 10 to hand value if it doesn't bust
- # compute the value of the hand, see Blackjack video
- # def draw(self, canvas, pos):
- # pass # draw a hand on the canvas, use the draw method for cards
- card1 = Card("S", 2)
- print "Card is %s" % str(card1)
- card2 = Card("H", "J")
- myHand = Hand()
- myHand.add_card(card1)
- myHand.add_card(card2)
- print "Hand is %s" % str(myHand)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement