class Player: def __init__(self, name): self.hand = Hand() self.name = name def take_card(self, card): self.hand.add_card(card) def get_score(self): return self.hand.get_value() def has_busted(self): return self.hand.get_value() > 21 def has_high_aces(self): return self.hand.get_high_aces() > 0 def adjust_for_ace(self): self.hand.adjust_for_ace() def show_some(self): last_card = self.hand.get_cards()[-1] print(f"\n{self.name}'s Card") print('================') print(f'{last_card.rank} of {last_card.suit}') print('================\n') def show_all(self): cards = self.hand.get_cards() print(f"\n{self.name}'s Cards") print('================') for index, card in enumerate(cards, start=1): print(f'Card {index}:') print(f'{card.rank} of {card.suit}') print('================\n') def reset_hand(self): self.hand = Hand()
def draw(player, dealer): print("Dealer and Player tie, Push.") while True: print("IT'S BLACKJACK TIME!") #Creating ShuffleDeck deck = Deck() deck.shuffle() #Make player hand add two cards and adjust for aces player_hand = Hand() player_hand.add_card(deck.deal()) player_hand.add_card(deck.deal()) player_hand.adjust_for_ace() #Make Dealer hand and adjust for 2 aces dealer_hand = Hand() dealer_hand.add_card(deck.deal()) dealer_hand.add_card(deck.deal()) dealer_hand.adjust_for_ace() #Player bet prompt player for a bet player_chips = Chips() make_bet(player_chips) #Showing cards but keeps one secret the one from the dealer show_some(player_hand, dealer_hand)
show_some(player, dealer) playing = hit_or_stand(deck, player, values) if player.aces != 0: while True: try: ace_decision = input( 'Would you like to adjust your ace? (y/n) ') except: print('Please enter a valid response.') continue if ace_decision == 'y' or ace_decision == 'n': break if ace_decision == 'y': player.adjust_for_ace() elif ace_decision == 'n': pass if player.value > 21: player_busts(bet, player_chips) print('Your chips balance is {}'.format(player_chips.total)) while True: try: play = input('Would you like to play again? (y/n) ') except: print('Please enter a valid response.') continue if play == 'y' or play == 'n': break if play == 'y':