#------------------------------------------------- # Project: chippies game # Standard: TE PUNGA - Programming Assessment # School: Tauranga Boys' College # Author: Alexander Rossiter # Date: March 2024 # Python: 3.7.4 #------------------------------------------------- #variables amountofrounds = 0 roundsplayed = 0 max_rounds = 5 p1score = 0 p2score = 0 max_chips = 21 # Player names input p1name = input("What's Player 1's name? ") p2name = input("What's Player 2's name? ") # Start of the game print("Welcome to my game!") print("In this game, you start with 21 chips.") print("You can only take away 1-3 chips at a time.") print("Once someone has taken away the last chip, they win the round.") print("Once one of you has won the round, it will carry out the amount of rounds you decided to play.") print("The person who's won the most rounds wins.") print("Now let's start playing!") # Function to play a round def play_round(player_name, chips_left): while True: chips_taken = int(input(f"{player_name}, pick a number between 1 and 3: ")) if 1 <= chips_taken <= 3 and chips_taken <= chips_left: break else: print("Invalid input! You can only take 1-3 chips, and there must be enough chips left.") chips_left -= chips_taken print(f"{player_name} took {chips_taken} chips.") return chips_left # Number of rounds selection while True: amountofrounds = int(input("How many rounds would you like to play (1-5)? ")) if 1 <= amountofrounds <= max_rounds: break else: print("Please pick a number between 1 and 5.") # Main game loop while roundsplayed < amountofrounds: chipsleft = max_chips while chipsleft > 1: print("Round:", roundsplayed + 1) print("Your stats:") print(f"{p1name} has taken {p1score} chips.") print(f"{p2name} has taken {p2score} chips.") print("Chips left:", chipsleft) # Player 1's turn chipsleft = play_round(p1name, chipsleft) if chipsleft <= 1: print(f"Good job {p1name}, you won this round!") p1score += 1 break # Player 2's turn chipsleft = play_round(p2name, chipsleft) if chipsleft <= 1: print(f"Good job {p2name}, you won this round!") p2score += 1 break roundsplayed += 1 # End of game print("Game over!") if p1score > p2score: print(f"The winner is {p1name}!") elif p2score > p1score: print(f"The winner is {p2name}!") #tie else: print("It's a tie!")