# ------------------------------------------------- # Project: Pick up game # Standard: TE PUNGA - Programming Assessment # School: Tauranga Boys' College # Author: Suvin Bandara # Date: March 2024 # Python: 3.7.4 # ------------------------------------------------- import time import random # constant variables MAX_CHIPS = 21 # Starting player score variables PlayerOneScore = 0 PlayerTwoScore = 0 # Chip setup chipsleft = 0 chipstaken = 0 # Asking for player names while True: name1 = str(input("What is the First player's name? ")) name2 = str(input("What is the second player's name? ")) if name1.isalpha() and name2.isalpha(): break else: print("A number is not an acceptable name!!!") # Checking variable integer input validation while True: try: rounds = int(input("How many rounds do you want to play? Type a number between 1 and 5: ")) if rounds < 1 or rounds > 5: # if player inputes a number of round more or less between 1 and 4 it will ask the player to input another number again which is valid print("It has to be between 1 and 5. Please try again.") else: break except: print("Please enter a number between 1 and 5") # Game loop for the rounds while rounds > 0: chipsleft = MAX_CHIPS print(f"\nStarting a new round: {rounds} rounds left") #shows the player how much rounds are left while chipsleft > 0: print(f"There are {chipsleft} chips left.") # shows the player how much chips are left during the games # Player 1's turn loop while True: try: chips_taken = int(input(f"How many chips does {name1} want to take? ")) # this ask the player to input a number of chips if chips_taken < 1 or chips_taken > 4: # if player iputs a number of chips more or less between 1 and 4 it will ask the player to input another number again which is valid print("You can only take between 1 and 4 chips.") elif chips_taken > chipsleft: print(f"Not enough chips left. Only {chipsleft} chips remain.") # if they input a number of chips to take away more than whats left it will ask the player again to choose a number between whats left else: break except : print("Please enter a valid number.") chipsleft -= chips_taken if chipsleft == 0: PlayerOneScore += 1 print(f"{name1} won this round!") break print(f"There are {chipsleft} chips left.") # Player 2's turn loop while True: try: chips_taken = int(input(f"How many chips does {name2} want to take? ")) if chips_taken < 1 or chips_taken > 4: print("You can only take between 1 and 4 chips.") elif chips_taken > chipsleft: print(f"Not enough chips left. Only {chipsleft} chips remain.") else: break except ValueError: print("Please enter a valid number.") chipsleft -= chips_taken if chipsleft == 0: PlayerTwoScore += 1 print(f"{name2} won this round!") break print(f"There are {chipsleft} chips left.") rounds -= 1 print(f"Scores after round: {name1}: {PlayerOneScore}, {name2}: {PlayerTwoScore}") # End of the game results to show if player 1 or 2 won the game depending on the round if PlayerOneScore > PlayerTwoScore: print(f"\n{name1} wins the game!") elif PlayerTwoScore > PlayerOneScore: print(f"\n{name2} wins the game!") else: print("\nIt's a draw!")