#-------------------------------------------------------------------------------------------------------------------------------------# #│ Name: Assesment 1 - 21 │ #│ │ #│ Author: Aidan Plummer │ #│ │ #│ Created: 18/03/2024 │ #│ Copyright: © Aidan Plummer 2024 │ #│ License: All rights reserved. This code is the intellectual property of Aidan Plummer. │ #│ You are granted permission to use this code for personal and educational purposes only. │ #│ Any commercial use, distribution, or modification of this code requires explicit permission from the author. │ #-------------------------------------------------------------------------------------------------------------------------------------# import random import time import os import sys # - Constants MAX_CHIPS = 21 # - Variables (Note all these variables are just being defined here, and will be defined in the later code.) player1Name = "" player2Name = "" player1Answer = 0 # - Player 1's Answer player2Answer = 0 # - Player 2's Answer player1Points = 0 # - Player 1's Round Score player2Points = 0 # - Player2's Round Score rounds = 0 # - Amount of rounds that will be played currentChips = 0 # - Current number the game is on currentPlayer = 0 # - Current player whos turn it is currentRound = 1 # - Current round the game loop is on def title(): # - Prints the visual title screen print("\n") print(" ▄▄▄▄▄▄▄ ▄▄ ▄▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄▄ ▄▄▄ ▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄▄ ▄ ▄ ▄▄▄▄▄▄ ▄▄ ▄▄ ▄▄▄▄▄▄▄ ▄▄▄▄▄▄ ▄▄ ▄▄ ▄▄▄▄▄▄▄ ") time.sleep(.1) print("█ █ █ █ █ █ █ █ █ █ █ █ █ █ █ ▄ █ █ █ █ █ █ █ █ █ █▄█ █ █") time.sleep(.1) print("█▄ ▄█ █▄█ █ ▄▄▄█ █▄ ▄█ ▄ █ █▄█ █ ▄▄▄█ ▄ █ ██ ██ █ ▄ █ █▄█ █ █ ▄▄▄▄█ ▄ █ █ ▄▄▄█") time.sleep(.1) print(" █ █ █ █ █▄▄▄ █ █ █ █▄█ █ ▄█ █▄▄▄█ █▄█ █ █ █▄█ █ █ █ █ ▄▄█ █▄█ █ █ █▄▄▄ ") time.sleep(.1) print(" █ █ █ ▄ █ ▄▄▄█ █ █ █ █ █▄█ ▄▄▄█ █ █ █▄ ▄█ █ █ █ █ █ █ ▄▄▄█") time.sleep(.1) print(" █ █ █ █ █ █ █▄▄▄ █ █ █ ▄ █ ▄ █ █▄▄▄█ ▄ █ ▄ █ ▄ █ █ █ █ █▄▄█ █ ▄ █ ██▄██ █ █▄▄▄ ") time.sleep(.1) print(" █▄▄▄█ █▄▄█ █▄▄█▄▄▄▄▄▄▄█ █▄▄▄█ █▄█ █▄▄█▄▄▄█ █▄█▄▄▄▄▄▄▄█▄█ █▄▄█▄▄█ █▄▄█▄█ █▄▄█ █▄▄▄█ █▄▄▄▄▄▄▄█▄█ █▄▄█▄█ █▄█▄▄▄▄▄▄▄█") time.sleep(.1) print("\n") def LoadingAnim(seconds): # - Prints a loading animation animation = ["[│]", "[/]", "[─]", "[╲]", "[│]", "[/]", "[─]", "[╲]", "[!]"] delay = seconds / 9 for i in range(len(animation)): time.sleep(delay) sys.stdout.write("\r" + animation[i % len(animation)]) sys.stdout.flush() print("\n") def clear_screen(): # - Clears all text in the output (helps with clutter) os.system('cls' if os.name=='nt' else 'clear') # - Start of running code clear_screen() title() LoadingAnim(1) print() print("Welcome to The Takeaway Game!") time.sleep(.1) print("The aim of the game is to be the player to take the last amount of chips (when chips go down to 0).") time.sleep(.1) print("(Note this is a 2 player game so grab your mate)") time.sleep(.1) # - Player 1's Name while True: player1Name = str(input("Player1 Name?: ")) if player1Name.isalpha() == True: break else: print("Error: Please input again.") # - Player 2's Name while True: player2Name = str(input("Player2 Name?: ")) if player2Name.isalpha() == True: break else: print("Error: Please input again.") # - Asks the user for the amount of rounds while True: try: print("") rounds = int(input("How many rounds do you want to play? [Max is 5] ")) if rounds < 1 or rounds > 5: print("Error: Invalid Number") else: break except: print("Error: Unknown Error, please try again") # - Start of Game Loop while rounds >= currentRound: currentChips = MAX_CHIPS currentPlayer = 1 clear_screen() LoadingAnim(1) while True: # - Round Loop print() print("Current number is at: {}".format(currentChips)) print("") print("{}'s turn. ".format(player1Name)) while True: # - Player 1's Turn try: print("") player1Answer = int(input("{} how many chips do you want to take? (1 - 3) ".format(player1Name))) if player1Answer < 1 or player1Answer > 3: print("Please choose a valid number between 1 - 3.") else: break except: print("Please choose a valid number between 1 - 3.") currentChips = currentChips - player1Answer # - Deducts the players answer from the total chips if currentChips <= 0: # - Checks if Player1 took the last chips print() player1Points = player1Points + 1 print("{} has won the round!".format(player1Name)) print() time.sleep(2) input("Press enter to continue") currentRound = currentRound + 1 break print() print("Current number is at: {}".format(currentChips)) print("") print("{}'s turn. ".format(player2Name)) while True: # - Player 2's Turn try: print("") player2Answer = int(input("{} how many chips do you want to take? (1 - 3) ".format(player2Answer))) if player2Answer < 1 or player2Answer > 3: print("Please choose a valid number between 1 - 3.") else: break except: print("Please choose a valid number between 1 - 3.") currentChips = currentChips - player2Answer # - Deducts the players answer from the total chips if currentChips <= 0: # - Checks if Player2 took the last chips print() player2Points = player2Points + 1 print("{} has won the round!".format(player2Name)) input("Press enter to continue") print() time.sleep(2) currentRound = currentRound + 1 break # - Game Ends and prints winner print("") if player1Points > player2Points: print("{} has won the game!".format(player1Name)) if player2Points > player1Points: print("{} has won the game!".format(player1Name)) if player1Points == player2Points: print("Game is a tie!")