""" ------------------------------------------------- Project: Pick-Up Game Standard: TE PUNGA - Programming Assessment School: Tauranga Boys' College Author: Joseph Fairbairn Date: 14/03/2024 Python: 3.11.9 ------------------------------------------------- """ import time # Starting Variables oneplayerscore = 0 # The scores of player 1 and 2 twoplayerscore = 0 # ^^^ ownedpoint = 0 # Proves which player gets the point chips = 21 # The Chips the players start with # Welcome Messages print("Welcome to the Pick-Up Game") time.sleep(1) print("Your goal in playing this game is to use your chips and " "beat your opponent in getting to 0 chips.") time.sleep(1) # Player Inputs while True: oneplayername = str(input("Enter a name for player 1 ")) # Asks for the players names and checks they are valid twoplayername = str(input("Enter a name for player 2 ")) # ^^^ if oneplayername.isalpha() == True and twoplayername.isalpha() == True: # Checks if the names are valid break else: print("Please enter valid names") while True: try: rounds = int(input("Enter the number of rounds you wish to play " + "\n")) # Asks for the number of rounds and checks they are valid if rounds < 1 or rounds > 5: print("Please enter a number between 1 and 5") else: break except: print("Please enter a number") # Functions - These functions are to shorten the code and repeat the game def chipsplayed(): global chips while True: try: chipsused = int(input("Enter the number of chips you wish to choose from 1 to 3 " + "\n")) # Asks for the number of chips and checks they are valid if chipsused < 1 or chipsused > 3: print("Please enter a number of chips between 1 and 3" + "\n") else: chips = chips - chipsused break except: print("Please enter a number" + "\n") def oneplayerturn(): global ownedpoint # Player 1's turn, prints their turn and how many chips they have, and sets ownedpoint to 1 to show which player's turn it is print(oneplayername + "'s turn") print("You have " + str(chips) + " chips left") ownedpoint = 1 def twoplayerturn(): global ownedpoint # Player 2's turn, prints their turn and how many chips they have, and sets ownedpoint to 2 to show which player's turn it is print(twoplayername + "'s turn") print("You have " + str(chips) + " chips left") ownedpoint = 2 def reset(): global chips # Resets the game chips = 21 # Game Loop while rounds > 0: # Loops the game until there are no more rounds while chips > 0: # Loops the game until there are no more chips and then resets the game oneplayerturn() chipsplayed() if chips <= 0: # Checks if there are no more chips inbetween turns break time.sleep(1) twoplayerturn() chipsplayed() time.sleep(1) else: rounds = rounds - 1 # Decreases the number of rounds and adds up the player scores then resets the game if ownedpoint == 1: oneplayerscore = oneplayerscore + 1 ownedpoint = 0 # Reset ownedpoint to 0 print("Player 1 - " + oneplayername + " has won the round" + "\n") elif ownedpoint == 2: twoplayerscore = twoplayerscore + 1 ownedpoint = 0 # Reset ownedpoint to 0 print("Player 2 - " + twoplayername + " has won the round" + "\n") reset() # Game Over print("Game Over") # Ends the game print("Player 1 - " + oneplayername + "'s score: " + str(oneplayerscore)) print("Player 2 - " + twoplayername + "'s score: " + str(twoplayerscore))