""" ------------------------------------------------- Project: Pick up game Standard: python School: Tauranga Boys' College Author: Jayden Harris Date: 14/03/2025 Python: 3.5 ------------------------------------------------- """ import time # Can be used for delays if needed # Function to get valid player names def get_player_name(player_number): while True: time.sleep(1) name = input("\nWhat is your name, Player {}? ".format(player_number)) if name.isalpha(): # Ensure name consists of letters only time.sleep(1) print("Hello, {}!".format(name)) return name else: print("Invalid name. Please enter letters only.") # Input and game variables chips_left = 21 # Chips reset every round chip_refresh = 21 # Constant for resetting chips rounds_played = 0 player_one_score = 0 player_two_score = 0 # Welcome message print("Hello, Welcome to the Pick Up Game!") # Ask for the number of rounds (between 1 and 5) while True: try: rounds_to_play = int(input("\nHow many rounds would you like to play? (1-5): ")) if 1 <= rounds_to_play <= 5: break else: print("Invalid choice. Please enter a number between 1 and 5.") except ValueError: print("Invalid input. Please enter a valid number.") # Get player names using function user_name_one = get_player_name(1) user_name_two = get_player_name(2) # Main game loop while rounds_played < rounds_to_play: time.sleep(1) print("\nRound {} of {}".format(rounds_played + 1, rounds_to_play)) chips_left = chip_refresh # Reset chips each round while chips_left > 0: # Continue until all chips are taken # Player One's Turn max_take = min(3, chips_left) # Limit max take to what's available while True: try: time.sleep(1) player_one_chips_take = int(input("\n{}, how many chips do you want to take? (1-{}): ".format(user_name_one, max_take))) if 1 <= player_one_chips_take <= max_take: # Ensure valid input range break else: print("Invalid choice. Choose between 1 and {}.".format(max_take)) except ValueError: print("Invalid input. Please enter a number.") player_one_score += player_one_chips_take # Update Player One's score chips_left -= player_one_chips_take # Reduce chips available time.sleep(1) print("{}'s points: {} | Chips left: {}".format(user_name_one, player_one_score, chips_left)) if chips_left == 0: break # End round if no chips left # Player Two's Turn max_take = min(3, chips_left) # Limit max take to what's available while True: try: time.sleep(1) player_two_chips_take = int(input("\n{}, how many chips do you want to take? (1-{}): ".format(user_name_two, max_take))) if 1 <= player_two_chips_take <= max_take: # Ensure valid input range break else: print("Invalid choice. Choose between 1 and {}.".format(max_take)) except ValueError: print("Invalid input. Please enter a number.") player_two_score += player_two_chips_take # Update Player Two's score chips_left -= player_two_chips_take # Reduce chips available time.sleep(1) print("{}'s points: {} | Chips left: {}".format(user_name_two, player_two_score, chips_left)) rounds_played += 1 # Move to next round # Determine the winner time.sleep(1) print("\nGame Over!") print("\n{}'s score: {}".format(user_name_one, player_one_score)) print("\n{}'s score: {}".format(user_name_two, player_two_score)) # Announce winner or tie time.sleep(1) if player_one_score > player_two_score: print("\nCongratulations, {}! You win with {} points!".format(user_name_one, player_one_score)) elif player_two_score > player_one_score: print("\nCongratulations, {}! You win with {} points!".format(user_name_two, player_two_score)) else: print("\nIt's a tie!")