#------------------------------------------------ # Project: Pick-Up Game # Standard: 91883 (AS1.7) v.1 # School: Tauranga Boys College # Author: Shay McDonald # Date: 27/03/2024 # Python: 3.5 #------------------------------------------------ # Sequences import time # This gives the ability to add time.sleep into my code turn = "" total_chips = 21 rounds_played = 0 round_number = 1 name1_score = 0 name2_score = 0 # Variables while True: play = input("Would you like to play? (y/n): ") if play.lower() != "y": break # While play equals yes run the code print("") name1 = input("Player 1 Name: ") name2 = input("Player 2 Name: ") # Asking the players what their names are def Name1_Turn(name1) : print(name1 + "'s", "Turn") def Name2_Turn(name2) : print(name2 + "'s", "Turn") # Using the define function to show whos turn it was while True: try: rounds = int(input("How many rounds would you like to play? (1-5): ")) if rounds < 1 or rounds > 5 : print("Please choose a number between 1 and 5") else: break except: print("") print("Please enter a valid number") # If a player chooses a number that is not between 1 and 5 it gives them and error and a chance to re renter while rounds_played < rounds : # While the amount of round choosen by the player is more than the rounds played so far print("") print("Round", round_number, "Is Starting...") time.sleep(1) while total_chips > 0 : # While there are more than 0 chips keep the round going turn = name1 print("") Name1_Turn(name1) print("") while True: try: chips_taken = int(input("Pick a number between 1-3: ")) if chips_taken < 1 or chips_taken > 3 : print("Please choose a number between 1 and 5") elif chips_taken > total_chips : print("") print("Not enough chips remaining!") print("") else: break except: print("") print("Please enter a valid number") total_chips = total_chips - chips_taken # The above 6 lines are running when it is player 1's turn print("") print("There Are", total_chips, "Chips Remaining") # Showing how many chips there are left after every turn if total_chips < 1 : break turn = name2 print("") Name2_Turn(name2) print("") while True: try: chips_taken = int(input("Pick a number between 1-3: ")) if chips_taken < 1 or chips_taken > 3 : print("Please choose a number between 1 and 5") elif chips_taken > total_chips : print("Not enough chips remaining!") else: break except: print("") print("Please enter a valid number") total_chips = total_chips - chips_taken # The above 6 lines are running when it is player 2's turn print("") print("There Are", total_chips, "Chips Remaining") # Showing how many chips there are left after every turn if total_chips < 1 : break # When there are zero chips the round ends if turn == name1 : name1_score += 1 else: name2_score += 1 round_number += 1 # Adding scores to winning player if round_number > rounds: break # Ending the game when all rounds have been played print("ROUND OVER") print("") print(turn, "Wins") print("") print(name1 + "'s Score =", name1_score) print(name2 + "'s Score =", name2_score) total_chips = 21 # Once a round is over reseting the chips back to 100 print("") print("GAME OVER") print("") if name1_score > name2_score : print(name1, "Wins!") else: print(name2, "Wins!") print("") print("Final Scores:") print(name1 + "'s Score =", name1_score) print(name2 + "'s Score =", name2_score) print("") # These 13 lines are run at the end of a round and shows who wons the round and the overall scores round_number = 1 play = input("Would you like to play again? (y/n): ") print("") # These 3 lines are run once all rounds have been played and ask if they would like to play again