""" ------------------------------------------------- Project: Take-Away Game Standard: 91883 (AS1.7) v.1 School: Tauranga Boys' College Author: Ishmael lethbridge Date: Python: 3.5 ------------------------------------------------- """ import time import random #Constant variables(number does not change) MAX_CHIPS = 21 #Variables(Most likely will change overtime) player1_score = 0 player2_score = 0 chips = 0 chipstaken = 0 rounds_played = 0 #Grabbing both of the players names while True: player1 = str(input("Player 1, what is your name?")) if player1.isalpha() == True: break else: print("That is not an acceptable name") while True: player2 = str(input("Player 2, what is your name?")) if player2.isalpha() == True: break else: print("That is not an acceptable name") #Greets the player and explains the instructions on how to play the game print("Welcome to the take away game", player1,"and", player2) time.sleep(0.76) print(f"--------INSTRUCTIONS--------") time.sleep(0.76) print("Take a certain amount of chips(between 1 and 3). Player 1 will start then player 2 will follow") time.sleep(0.76) print("The person who takes the last chip wins the round") time.sleep(0.76) print("Who ever comes out with the highest score at the end of the maximum 5 rounds wins") time.sleep(0.76) print("If you don't follow the rules your turn will be skipped without a warning") time.sleep(0.76) print(f"Best of luck to you both {player1}, and {player2}") #Players pick the amount of rounds while True: rounds = int(input("how many rounds do you want to play? 1-5 : ")) if rounds < 1 or rounds > 5: #If the user inputs a number above 5 or below 0 then it asks for the amount of rounds again print("Please choose a number between 1 and 5") else: break #Starting the main game loop while rounds > 0 : #sets the starting chips to max_chips(21) then displays the score and rounds then the amount of chips chipsleft = MAX_CHIPS print(f"{player1}'s score = ", player1_score, f"{player2}'s score = ", player2_score) print(f"Rounds - {rounds}") print("there are ", chipsleft,"chips left") print("-----------------------------------") while chipsleft > 0 : #starts the game with player1 taking the first set of chips print(f"{player1} its your turn!") print("there are ", chipsleft,"chips left") chipstaken = int(input("How many chips do you want to take away from the stack between 1 and 3: ")) print("-----------------------------------") if chipstaken > 3 or chipstaken < 1: print("pick a number between 1 and 3") else: chipsleft -= chipstaken #if there are no chips left then the player who took the chips in this instance would be player 1 would win the round and adds +1 score onto their score if chipsleft <= 0 : player1_score = player1_score + 1 print(f"{player1} WINS THIS ROUND!") rounds = rounds - 1 break print(f"{player2} its your turn!") print("there are ", chipsleft,"chips left") #this is player 2's turn which is pretty much the exact same code as player 1's chipstaken = int(input("How many chips do you want to take away from the stack between 1 and 3: ")) print("-----------------------------------") if chipstaken > 3 or chipstaken < 1 : print("pick a number between 1 and 3") else: chipsleft -= chipstaken #if there are no chips left then the player who took the chips in this instance would be player 1 would win the round and adds +1 score onto their score if chipsleft <= 0 : player2_score = player2_score + 1 print(f"{player2} WINS THIS ROUND!") rounds = rounds - 1 break #displays final score and then detects who wins the game if rounds == 0 : print(f"{player1}'s score = ", player1_score, f"{player2}'s score = ", player2_score) if player1_score > player2_score : print(f"{player1} wins! Good Game") else: print(f"{player2} Wins! Good Game") if player1_score == player2_score : print(f"its a tie! you might aswell play again...")