Created
November 3, 2020 16:39
-
-
Save Piwero/b8051fe38336437aceffa8521f8997bf to your computer and use it in GitHub Desktop.
Blackjack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while True: | |
# Print an opening statement | |
print("Welcome to Blackjack") | |
# Create & shuffle the deck, deal two cards to each player | |
new_deck = Deck() | |
new_deck.shuffle() | |
player_hand = Hand() | |
player_hand.add_card(new_deck.deal()) | |
player_hand.add_card(new_deck.deal()) | |
dealer_hand = Hand() | |
dealer_hand.add_card(new_deck.deal()) | |
dealer_hand.add_card(new_deck.deal()) | |
# Set up the Player's chips | |
player_chips = Chips() | |
# Prompt the Player for their bet | |
take_bet(player_chips) | |
# Show cards (but keep one dealer card hidden) | |
show_some(player_hand,dealer_hand) | |
while playing: # recall this variable from our hit_or_stand function | |
# Prompt for Player to Hit or Stand | |
hit_or_stand(new_deck,player_hand) | |
# Show cards (but keep one dealer card hidden) | |
show_some(player_hand,dealer_hand) | |
# If player's hand exceeds 21, run player_busts() and break out of loop | |
if player_hand.value >21: | |
player_busts(player_hand,dealer_hand,player_chips) | |
break | |
# If Player hasn't busted, play Dealer's hand until Dealer reaches 17 | |
if player_hand.value<=21: | |
while dealer_hand.value <17: | |
hit(new_deck,dealer_hand) | |
# Show all cards | |
show_all(player_hand,dealer_hand) | |
# Run different winning scenarios | |
if player_hand.value< dealer_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) | |
elif dealer_hand.value> 21: | |
dealer_busts(player_hand,dealer_hand,Playeer_chips) | |
else: | |
push(player_hand,dealer_hand) | |
# Inform Player of their chips total | |
print("Player 1, you still have {player_chips.total} chips ") | |
# Ask to play again | |
new_game= input("Do you want to play again y or n?") | |
if new_game[0].lower() == "y": | |
playing=True | |
continue | |
else: | |
print('Thanks for playing. BYE!') | |
break |
` # Run different winning scenarios
if player_hand.value< dealer_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)
elif dealer_hand.value> 21:
dealer_busts(player_hand,dealer_hand,Playeer_chips)`
Playeer_chips = wrong functionalists called
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm going to improve this code