print("\033c") #-------------------------------------------------------------------------- # Name : BlackJack # Purpose : 11DGT # Author: Oscar Nicholas # Created : 2024 # Copyright : © Oscar Nicholas 2024 #-------------------------------------------------------------------------- import os import time import random total_deck = 0 def display_banner(): print("-----------------------------------------------------------") print("┏━━┓ ┏┓ ┏━━━┓ ┏━━━┓ ┏┓┏━┓ ┏┓ ┏━━━┓ ┏━━━┓ ┏┓┏━┓ ") print("┃┏┓┃ ┃┃ ┃┏━┓┃ ┃┏━┓┃ ┃┃┃┏┛ ┃┃ ┃┏━┓┃ ┃┏━┓┃ ┃┃┃┏┛ ") print("┃┗┛┗┓ ┃┃ ┃┃ ┃┃ ┃┃ ┗┛ ┃┗┛┃ ┃┃ ┃┃ ┃┃ ┃┃ ┗┛ ┃┗┛┃ ") print("┃┏━┓┃ ┃┃ ┏┓ ┃┗━┛┃ ┃┃ ┏┓ ┃┏┓┃ ┏┓┃┃ ┃┗━┛┃ ┃┃ ┏┓ ┃┏┓┃ ") print("┃┗━┛┃ ┃┗━┛┃ ┃┏━┓┃ ┃┗━┛┃ ┃┃┃┗┓ ┃┗┛┃ ┃┏━┓┃ ┃┗━┛┃ ┃┃┃┗┓ ") print("┗━━━┛ ┗━━━┛ ┗┛ ┗┛ ┗━━━┛ ┗┛┗━┛ ┗━━┛ ┗┛ ┗┛ ┗━━━┛ ┗┛┗━┛ ") print("-----------------------------------------------------------") print() def deal_card(): card = random.choice([2, 3, 4, 5, 6, 7, 8, 9, 10, 'Jack', 'Queen', 'King', 'Ace']) if card == 'Ace': value = input("You pulled an Ace. Do you want the Ace to be a [1] or an [11]? ").lower() while value not in ['1', '11']: print("Invalid input! Please pick 1 or 11") value = input("You pulled an Ace. Do you want the Ace to be a [1] or an [11]? ").lower() print(f'Your Ace is now worth {value} point(s)') return int(value) elif card in ['Jack', 'Queen', 'King']: print(f"You picked up a {card} worth 10 points") return 10 else: print(f"You picked up a simple {card}") return card def dealer_card(): deal_dealer = random.choice([2, 3, 4, 5, 6, 7, 8, 9, 10, 'Jack', 'Queen', 'King', 'Ace']) if deal_dealer == 'Ace': if total_dealerdeck <= 10: Ace = 11 elif total_dealerdeck > 10: ace = 1 print(f"Dealer has picked up an Ace and valued it at {Ace}") total_dealerdeck =+ Ace elif deal_dealer in ['Jack', 'Queen', 'King']: print(f"Dealer picked up a {deal_dealer} worth 10 points") return 10 else: print(f"Dealer picked up a simple {deal_dealer}") return deal_dealer def play_round(): global total_deck total_deck = 0 dealersdeck = 0 dealersdeck += dealer_card() print("Dealer picked up one other card...") print() total_deck += deal_card() total_deck += deal_card() print() print(f"Your total: {total_deck}") while total_deck <= 21: hop = input("Do you want to [h]it or [p]ass? ") if hop == 'h': total_deck += deal_card() print(f"Your total: {total_deck}") elif hop == 'p': break else: print("Invalid input! Please choose 'h' or 'p'. ") print() while dealersdeck < 17: dealersdeck += dealer_card() print(f"Dealer's total: {dealersdeck}") if total_deck <= 21: if dealersdeck > 21 or total_deck > dealersdeck: print("You won!") elif total_deck == dealersdeck: print("It's a tie!") else: print ("You lost!") else: print("You busted! Dealer wins.") end_game() def end_game(): print() restart = input("Type m to go back to menu: ") if restart == 'm': menu() menu() def start_game(): os.system('cls||clear') display_banner() play_round() def show_rules(): print("1. The dealer shuffles the deck and deals two cards to each player, including themselves. All cards are dealt face up.") time.sleep(2) print("2. Each player's hand is the sum of the card values. Players can see their own cards but not the dealer's other card.") time.sleep(2) print("3. A ton of other rules, ect, ect, ect.") def show_credits(): print() print ("#--------------------------------------------------------------------------") print ("# Name : BlackJack") print ("# Version: v1.11") print ("# Author: Oscar Nicholas") print ("# Created : 2024") print ("# Copyright : © Oscar Nicholas 2024") print ("#--------------------------------------------------------------------------") os.system('cls||clear') def menu(): os.system('cls||clear') display_banner() start = input("[s]tart, [r]ules or [c]redits: ").lower() if start == "s": start_game() elif start == "r": show_rules() print() restart = input("Type m to go back to menu: ") if restart == 'm': menu() elif start == "c": show_credits() print() restart = input("Type m to go back to menu: ") if restart == 'm': menu() else: menu() while True: menu()