""" ------------------------------------------------- Project: Pick-Up Game Standard: TE PUNGA - Programming Assessment School: Tauranga Boys' College Author: Max Warrender Date: 14th Of March 2024 Python: 3.13 ------------------------------------------------- """ import time # Constants # The Chips the players start with and resets chips_left left_over_chips = 21 # Starting Variables #Player 1/2s score at start. player1score = 0 player2score = 0 #Identifies who wins. player_point = 0 #Chips left over chips_left = 0 #Functions for the entire game (reduces repetition) def chips_spent(): #Lets players choose the amount of chips they would like to play global left_over_chips global chips_left while True: try: player_chips = int(input("Enter the number of chips you'd like to play (From 1 to 3) ")) if player_chips < 1 or player_chips > 3: print("Please enter a number of chips between 1 and 3") else: #Takes away player chips from the starting chips chips_left = chips_left - player_chips break except: #Makes them renter if they have not put a number print("Please enter a number (You may have added a space)") def player1_turn(): #This is player ones turn. global player_point print(name1 + "'s turn") print("You have {} chips left".format(chips_left)) player_point = 1 def player2_turn(): #This is plater twos turn. global player_point # print(name2 + "'s turn") print("You have {} chips left".format(chips_left)) player_point = 2 def new_game(): #Restarts the game for the next round global left_over_chips global chips_left chips_left = left_over_chips #Introduction/Welcome print("You are playing the pickup game.") time.sleep(0.5) print("The goal of the game is to get the number of chips remaining to 0 before the other player, which will give you a point.") # Player Inputs while True: name1 = str(input("Player 1, please enter a name: ")) name2 = str(input("Player 2, please enter a name: ")) #Allows the game to countinue if name1.isalpha() == True and name2.isalpha() == True: break #Makes player reneter a name as it is invalid. else: print("These names are invalid, and need to be reentered.") while True: try: rounds= int(input("How many rounds would you like to play (Please choose a number between 1 and 5?) ")) #If rounds = less than 1 or more than 5, it asks the players again. if rounds < 1 or rounds > 5: print("Please choose a number between 1 and 5") else: #Lets the players continue because they have entered a number between 1-5 break except: #If rounds = a letter or doesn't answer at all, asks again print("Thats not even a number????") #Gameplay while rounds >= 0: while chips_left > 0: # Loops the game until there are no more chips and then resets the game player1_turn() chips_spent() if chips_left <= 0: # Checks if there are no more chips inbetween turns break player2_turn() chips_spent() else: rounds = rounds - 1 #Proves player 1 has won the round by identifying the player point if player_point == 1: player1score = player1score + 1 #Makes the player point reset player_point = 0 print("-------------------") print("{} won the round".format(name1)) print("-------------------") #Proves player 2 has won the round by identifying the player point elif player_point == 2: player2score = player2score + 1 #Makes the player point reset player_point = 0 print("-------------------") print("{} won the round".format(name2)) print("-------------------") new_game() #end of game print("Game Over") #Prints the players scores. print("{} score: {}".format(name1, player1score)) print("{} score: {}".format(name2, player2score))