def play_dealer_hand(dealer_hand):
    card = playing_cards.deal_one_card()
    points = get_hand_total(dealer_hand)
    while points < 17:
        card = playing_cards.deal_one_card()
        dealer_hand.append(card)
        points = get_hand_total(dealer_hand)
        print("Dealer's hand is", points)
        display_hand(dealer_hand)
    if points > 21:
        print('Dealer busts!')
    return dealer_hand
Exemplo n.º 2
0
def play_player_hand(player_hand):

    #The function asks the useer whether they want to hit or stand
    print()
    what_user_chose = get_hit_choice()

    #The loop runs if the player has chosen to hit and adds a card to the player's hand
    while what_user_chose == "h":
        
            card = playing_cards.deal_one_card()
            player_hand.append(card)
            print()
            display_hand("Player's hand is", player_hand)

            #If the player's hand goes above 21, the player busts
            if get_hand_total(player_hand)>21:
                
                what_user_chose = "s"
                print("--> Player busts!")

            #If the player's hand does not, it asks what they want to do again    
            elif get_hand_total(player_hand) <= 21:
                
                print()
                what_user_chose = get_hit_choice()

    #This checks if the player has stood while having a hand of less than 15 and forces them to take a card            
    while what_user_chose == "s" and get_hand_total(player_hand)<15:
        
        print()
        print("Cannot stand on value less than 15!")
        card = playing_cards.deal_one_card()
        player_hand.append(card)
        print()
        display_hand("Player's hand is", player_hand)

        #If the player goes over 21, they bust
        if get_hand_total(player_hand)>21:
            
            what_user_chose = "s"
            print("--> Player busts!")

        #Else they get asked to hit or stand again    
        else:
            print()
            what_user_chose = get_hit_choice()
def get_hit_choice():
    hit_choice = input("Please enter h or s (h = Hit, s = Stand):")
    points = get_hand_total(player_hand)
    while hit_choice != 'h' and hit_choice != 's':
        hit_choice = input("Please enter h or s (h = Hit, s = Stand):")
    if hit_choice == 'h':
        card = playing_cards.deal_one_card()
        player_hand.append(card)
    if hit_choice == 's' and points >= 15:
        player_hand == player_hand
        points = get_hand_total(player_hand)
        print("player's hand is", points)
        display_hand(player_hand)

    elif hit_choice == 's' and points < 15:
        print('Cannot stand on values less than 15!')
        card = playing_cards.deal_one_card()
        player_hand.append(card)
    return hit_choice
Exemplo n.º 4
0
def play_dealer_hand(dealer_hand):

    #Display's the dealer's hand and then proceeds to add cards to the dealers hand while it is less than 17
    display_hand("Dealer's hand is", dealer_hand)
    
    while get_hand_total(dealer_hand)<17:
        
        card = playing_cards.deal_one_card()
        dealer_hand.append(card)
        display_hand("Dealer's hand is", dealer_hand)

        #if the dealer's hand goes over 21 they bust
        if get_hand_total(dealer_hand) > 21:
            print("--> Dealer busts!")
        display_hand(dealer_hand)
    if points > 21:
        print('Dealer busts!')
    return dealer_hand


player_hand = []
dealer_hand = []
points = 0
play_choice = input('would you like to play blackjack? :')
while play_choice != 'y':
    play_choice = input('would you like to play blackjack? :')
if play_choice == 'y':

    # deal first card
    card = playing_cards.deal_one_card()
    # append one card to dealer_hand list
    dealer_hand.append(card)
    # append it to the player_hand list
    card = playing_cards.deal_one_card()
    player_hand.append(card)

    # deal second card
    card = playing_cards.deal_one_card()

    # append it to the player_hand_list
    player_hand.append(card)

    # total dealer's hand and display
    points = get_hand_total(dealer_hand)
    print("dealer's hand'is", points)