#--------------------------------------------------------------------------# # Name : 21CardGame # # Purpose : 11DGT # # Author: Lincoln # # Created : 19/02/2024 # # Copyright : © Lincoln 28/02/2024 # #--------------------------------------------------------------------------# #Imports import random import time #Values START_DEALER_VALUE = 0 START_PLAYER_VALUE = 0 retry = "y" rules = 'n' hit = "h" Player_Value = 0 Dealer_Value = 0 playercard1 = 0 playercard2 = 0 playercardhit = 0 dealercard1 = 0 dealercard2 = 0 dealercardhit = 0 #Spacing def spacing() : print("") #Introduction def intro() : spacing() print("Welcome to 21 card game") time.sleep(1) spacing() rules = input("Do you want to hear the rules? (y/n): ") if rules == "y": yrules() elif rules == "n" : nrules() #Restart def restart() : spacing() retry = input("Do you want to play again? (y/n): ") if retry == "y" : main() elif retry == "n" : spacing() print("Ok then goodbye.") #Rules def yrules() : spacing() print("The rules are simple") time.sleep(1) spacing() print("The aim of the game is to get as close as you can to 21 without going over") time.sleep (3) spacing() print("If you get a higher number then the dealer or the dealer busts then you win") time.sleep(3) spacing() print("This rule is vice versa") time.sleep(1) spacing() print("If you go over 21 or the dealers number is higher then yours then you lose") time.sleep(3) spacing() print("Every card has it own value") time.sleep(1) spacing() print("Numbered cards have the value of their number while Kings Queens and Jacks have a value of 10") time.sleep(3) spacing() print("Aces are unique as they can have a value of 1 or 11") time.sleep(2) spacing() print("You and the dealer start with 2 cards") time.sleep(1) spacing() print("You can either hit or stand") time.sleep(1) spacing() print("Hitting will get you another card while standing will stop you from getting another card") time.sleep(3) spacing() print("Now let us get started...") time.sleep(1) main() #Folded def Folded(): print("Your final score was {}." .format(Player_Value)) #Skip rules def nrules(): spacing() print("Let us begin then") time.sleep(1) main() #Main Script def main(): while retry == "y" : Player_Value = START_PLAYER_VALUE playercard1 = random.randint(1,12) playercard2 = random.randint(1,12) Dealer_Value = START_DEALER_VALUE dealercard1 = random.randint(1,12) dealercard2 = random . randint(1,12) ace() while hit == "h" or Player_Value < 21 : spacing() hit=input("Hit or Fold? (h/f): ") if hit == "f" : Folded() elif hit == "h" : playercardhit = 0 dealercardhit = 0 #Kings, Queens or Jacks def royal(): print() #Aces def ace(): if playercard1 == 11 and Player_Value > 21 : Player_Value -= 10 playercard1 == 1 if playercard2 == 11 and Player_Value > 21 : Player_Value -= 10 playercard2 == 1 if dealercard1 == 11 and Dealer_Value > 21 : Dealer_Value -= 10 dealercard1 == 1 if dealercard2 == 11 and Dealer_Value > 21 : Dealer_Value -= 10 dealercard2 == 1 intro()