import games, cards class Card(cards.GenericCard): ACE_VALUE = 1 def get_value(self): if self.is_face_up: value = Card.RANKS.index(self.rank) + 1 if value > 10: value = 10 else: value = None return value value = property(get_value) class Deck(cards.GenericDeck): pass # simplified by us (correctly) class Hand(cards.GenericHand): def __init__(self, name): super(Hand, self).__init__() self.name = name def __str__(self): rep = self.name + ":\t" + super(Hand, self).__str__() if self.total: rep += "(" + str(self.total) + ")" return rep def get_total(self): for card in self.cards: if not card.value: return None total = 0 for card in self.cards: total += card.value contains_ace = False for card in self.cards: if card.value == Card.ACE_VALUE: contains_ace = True break if contains_ace and total <= 11: total += 10 return total total = property(get_total) def is_busted(self): return self.total > 21 class Dealer(Hand): def is_hitting(self): return self.total < 17 def bust(self): print self.name, "busts." def flip_first_card(self): first_card = self.cards[0] first_card.flip() class Player(Hand): def bust(self): print self.name, "busts" def push(self): print self.name, "pushes." class Game(object): def __init__(self, names): self.players = [] for name in names: player = Player(name) self.players.append(player) self.dealer = Dealer('Dealer') self.deck = Deck() self.deck.populate() self.deck.shuffle() def play(self): print "Ha, ha!" def main(): print "\t\tWelcome to BlackJack!\n" names = [] number = games.ask_number("How many players? (1 - 7):", low = 1, high = 8) for i in range(number): name = raw_input("Enter player name: ") names.append(name) print game = Game(names) again = None while again != 'n': game.play() again = games.ask_yes_no("\nDo you want to play again [y/n]?: ") # find a way to repopulate and reshuffle the cards in the deck print "Good, we get to go home..."