Exemple #1
0
def main():
    global playing
    print("Welcome to Blackjack")

    player_name = input("What's your name? ")
    player_hand = classes.Hand(player_name)
    dealer_hand = classes.Hand("dealer")

    while True:
        try:
            player_total = int(input("How much are you bringing to the table? "))
            player_chips = classes.Chips(player_total)
            break
        except:
            print("We are sorry, this is an inappropriate value for your chips.")

    while True:
        deck = classes.Deck()
        deck.shuffle()

        functions.take_bet(player_chips)
        print("\n")

        player_hand.add_card(deck.deal())
        player_hand.add_card(deck.deal())

        dealer_hand.add_card(deck.deal())
        dealer_hand.add_card(deck.deal())

        functions.show_some(player_hand, dealer_hand)
        while playing:
            playing = functions.player_action(deck, player_hand)
            print("\n")
            functions.show_some(player_hand, dealer_hand)

            if player_hand.value > 21:
                functions.player_busts(player_hand, dealer_hand, player_chips)
                break
            


        if player_hand.value <= 21:
            functions.show_all(player_hand, dealer_hand)
            input("Press Enter to Continue ...")

            if dealer_hand.value < 17:
                print("The dealer has elected to hit:")
                dealer_hand.add_card(deck.deal())
                functions.show_all(player_hand, dealer_hand)
                input("Press Enter to Continue ...")

            if dealer_hand.value > 21:
                functions.dealer_busts(player_hand, dealer_hand, player_chips)

            elif dealer_hand.value > player_hand.value:
                functions.dealer_wins(player_hand, dealer_hand, player_chips)

            elif dealer_hand.value == player_hand.value:
                functions.push(player_hand, dealer_hand, player_chips)

            else:
                functions.player_wins(player_hand, dealer_hand, player_chips)

        if player_chips.total == 0:
            print("You have no more chips to play with, thank you for playing.")
            break

        action = input("Do you wish to play again? (y/n) ")

        if action[0].lower() == "n":
            break

        player_hand.clean_hand()
        dealer_hand.clean_hand()
        playing = True
Exemple #2
0
    # Asks the player if he wants another card, loops as long as the player wants more cards
    while functions.playing:
        functions.hit_or_stand(deck, player)
        # stops the game and shows the cards if the player busted
        if functions.bust(player):
            functions.show_all(player, dealer)
            functions.dealer_wins(chips)
            break
        # shows the cards after each new card drawn
        else:
            functions.show_some(player, dealer)
    # Dealer draws until he has equal or more points than the player
    while dealer.value <= player.value:
        if dealer.value < 21:
            functions.hit(deck, dealer)

    # Shows all the cards
    functions.show_all(player, dealer)

    # Decides the game winner
    if functions.bust(dealer):
        functions.player_wins(chips)
    elif player.value == dealer.value:
        functions.push()

    # Asks the player if he wants to continue playing
    if functions.replay(chips) == 'n':
        break
    else:
        functions.playing = True
Exemple #3
0
    while playing:
        hit_or_stand(the_deck, player)
        show_some(player, dealer)

        if player.value > 21:
            player_busts(player, dealer, player_chips)
            break

    if player.value <= 21:
        while dealer.value >= 17:
            hit(the_deck, dealer)
            show_all(player, dealer)
        if dealer.value > 21:
            dealer_busts(player, dealer, player_chips)
        elif dealer.value > player.value:
            dealer_wins(player, dealer, player_chips)
        elif dealer.value < player.value:
            player_wins(player, dealer, player_chips)
        else:
            push(player, dealer)

    new_game = input("Would you like to play another hand? Enter Y or N")

    if new_game[0].lower() == 'y':
        playing = True
        continue
    else:
        print("Thanks for playing!")
        break
        while dealer_hand.value < player_hand.value:
            hit(deck, dealer_hand)

        #show all cards
        show(player_hand, dealer_hand)

        #Winning scenarios

        if dealer_hand.value > 21:
            dealer_busts(player_hand, dealer_hand, player_chips)

        elif dealer_hand.value > player_hand.value:
            dealer_wins(player_hand, dealer_hand, player_chips)

        elif dealer_hand.value < player_hand.value:
            player_wins(player_hand, dealer_hand, player_chips)

        else:
            push(player_hand, dealer_hand)

    print("\nPlayer you have {} chips available".format(player_chips.total))

    #Ask to play again

    ask = input("Want to play again? y/n").lower()

    if ask[0] == 'y':
        print("OK! Get ready for next round!")
        playable = True
    else:
        print("Thank You for playing!")
Exemple #5
0
            # take computer bet
            computer_bet(computer_chips.total, pot)

            # merge cards
            player_cards = player.hand + table.table
            computer_cards = computer.hand + table.table

            #player score and rank
            player_score, player_rank = check_rank(player_cards)

            # computer score and rank
            computer_score, computer_rank = check_rank(computer_cards)

            # see who wins
            if computer_score > player_score:
                computer_wins(computer_cards, computer_rank, player_bets,
                              player_chips)
            elif computer_score < player_score:
                player_wins(player_cards, player_rank, player_chips, pot,
                            player_bets)

            # finish this round
            break

    else:
        print(f"You finished with {player_chips.total} chips")
        print("Come again!")
        break

#os.chdir(old_dir)