# #------------------------------------------------------------------------# # | Name : Card Game | # | Purpose : 11DGT | # | Author: Hayden De Rohan | # | Created : 28/02/2024 | # | Finished : | # | Copyright : © Hayden De Rohan 28/02/2024 | # #------------------------------------------------------------------------# import random import time # Variables Player_Hand = [] # FUNCTIONS def GameStartUp() : GiveStartingHand() print("Your current hand {}".format(Player_Hand)) HandsValue = ProccessValue(Player_Hand) print("Total value = {}".format(HandsValue)) print() print() def Cards() : possibleCards = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, "Ace", "Queen", "King", "Jack"] ChoosenCards = [] for i in range(1,21) : randomthing = random.choice(possibleCards) ChoosenCards.append(randomthing) CardToDraw = random.choice(ChoosenCards) Player_Hand.append(CardToDraw) return CardToDraw def GiveStartingHand() : for i in range(1,3) : Roll = Cards() def ProccessValue(HandCards) : Value = 0 for item in HandCards : if isinstance(item, int) : Value += item elif isinstance(item, str) : if item == "Queen" : Value += 10 elif item == "King" : Value += 10 elif item == "Jack" : Value += 10 elif item == "Ace" : Value += 11 # 11 for now return Value def Scroll() : for i in range(1,18) : print() def Spacing() : print() print() def Rules() : time.sleep(0.35) print("Rules :") time.sleep(0.35) print("Type all inputs as !!lowercase!!") time.sleep(0.35) print("Aim of the 21 Card Game is to get 21 or as close to as possible, without going over 21 else you'll lose") time.sleep(0.35) print("You start with 2 cards and can choose o sit out or take a card every turn.") time.sleep(0.35) print("You are playing against the dealer who is also trying to get 21") time.sleep(0.35) print("If the game results in both players having 21 it'll be a draw") time.sleep(0.35) print("Your goal is to not bust, while trying to score higher then the dealer or as close to 21 as possible") def MainScript() : Rules() time.sleep(0.5) Scroll() GameStartUp() while True : Final_Value = ProccessValue(Player_Hand) while Final_Value < 22 : Hit_Or_Not = input("Do you Hit or Fold? -- ") if Hit_Or_Not == "hit".casefold() : Draw = Cards() Final_Value = ProccessValue(Player_Hand) Spacing() print("You drew a {}".format(Draw)) print(Player_Hand) print("You're hands current total value is = [{}]".format(Final_Value)) Spacing() elif Hit_Or_Not == "fold".casefold() : Final_Value = ProccessValue(Player_Hand) Spacing() print("You folded with a hand of {}".format(Player_Hand)) print("You're final total value was = [{}]".format(Final_Value)) print("The score the AI has to beat is", (21 - Final_Value)) Spacing() break else : Spacing() print("You did type 'hit' or 'fold' do that next time!") Spacing() if Final_Value == 21 : Spacing() print("You Won") break else : Spacing() print("You busted!") Spacing() break # Start the game if __name__ == "__main__" : Spacing() print(" -- Game Worked -- ") Spacing() MainScript() else : print("Didn't work LMAOOOOO")