""" ------------------------------------------------- Project: Pick Up Game Standard: TE PUNGA - Programming Assessment School: Tauranga Boys' College Author: Gareth Willats Date: March 2025 Python: 3.11.9 ------------------------------------------------- """ #Imports import time import random #Importing modules to help us access the time and a randomness to easy access. #----------------------------------------------------------------------------------- #Defines def turn(): firstPlayer = name if turn == 1 else name2 def sleep1s(): time.sleep(1) def sleep2s(): time.sleep(2) def sleep3s(): time.sleep(3) #Used for easy access of quick code and helping clean things up. #----------------------------------------------------------------------- #Constant variables. MAX_CHIPS = 21 #Variables that won't change. #-------------------------------------- #Variables. name = "" name2 = "" turn = 0 rounds = 0 playerOneScore = 0 playerTwoScore = 0 chipsLeft = MAX_CHIPS chipsTaken = 0 #Variables that are changed and affected by the code. #-------------------------------------------------------- #Input & Validation codes. #Firsly the name inputs with validation checks. while True: name = str(input("What is player one's name?")) if name.isalpha() == True: #||#'isalpha' is an outputing code that either gives a true or false output. sleep1s() #Sleeping ||#If the input is a string, it will output true, and if it is an integer, it will output false. name2 = str(input("What is player two's name?")) if name2.isalpha() == True: break if name2.isalpha() == False: print("That is not an acceptable name, and yes i am in fact namist.") if name.isalpha() == False: print("That is not an acceptable name, and yes i am in fact namist.") #Secondly the round inputs with a validation check. while True: try: rounds = int(input("How many rounds do you desire to face thou? Said acquired number shall not exceed said bounds of 1-5.")) if rounds < 1 or rounds > 5: sleep1s() print("Choose a number between 1 and 5 ya nincompoop!") else: break except: sleep1s() print("That was not a number you unhearty comrade!") #The code asking for a string correct name and then an integer correct name. #--------------------------------------------------------------------------------- turn = random.randint(1,2) firstPlayer = name if turn == 1 else name2 sleep1s() #Main game loop while rounds > 0: chipsLeft = MAX_CHIPS #Chip reset for each round. while chipsLeft > 0: sleep1s() print("There are", chipsLeft, "chips left.") sleep1s() print(firstPlayer,"""'s turn.""") #player input to choose how many chips they want to take. while True: try: chipsTaken = int(input("How many tokens of said game are you willing to take?")) if 1 <= chipsTaken <= 3: break else: print("You must pick between 1-3 chips you maniac!") except ValueError: #Outputs if the chipsTaken is actually a number. print("Please enter a valid number") chipsLeft -= chipsTaken #The part where it checks if the game is over. if chipsLeft <= 0: #This code basically asks if the last few chips are taken. print(firstPlayer, "took the last chip") if firstPlayer == name: playerOneScore += 1 else: playerTwoScore += 1 #This block deals with the rounds and the maths behind them. rounds -= 1 print("There are", rounds, "rounds left.") print("Current Score: [Player One - Player Two]: ", playerOneScore, "-", playerTwoScore) #Swapping the starting player so the next game can switch them. firstPlayer = name if firstPlayer == name2 else name break #We now exit THIS loop to start the new rounds. #Swapping the turns firstPlayer = name if firstPlayer == name2 else name2 #Checking for the winner. sleep2s() if playerOneScore > playerTwoScore: print(name, "wins the game!") elif playerTwoScore > playerOneScore: print(name2, "wins the game!") else: print("NO ONE WINS YOU ALL LOSE!") print("Hope you had fun!")