""" ------------------------------------------------- Project: Take-Away Game Standard: 91883 (AS1.7) v.1 School: Tauranga Boys' College Author: Lucas Coster Date: THE DATE YOU COMPLETED THE CODE Python: 3.5 ------------------------------------------------- """ import time #After the round ends max_chips = 21 #The base variables for at the start of the game player1_score = 0 player2_score = 0 rounds_played = 0 chips = 0 num_chips = 0 #Explaining the instructions and rules of the game print("-----INSTRUCTIONS-----") time.sleep(0.5) print("You pick to play from 1-5 rounds. The aim of the games is to take the last chip. The catch is that you can only take 1-3 chips each turn.") time.sleep(0.5) print("-----RULES-----") time.sleep(0.5) print("Rule 1 - Dont take more then 1-3 chips or your turn will be skipped") time.sleep(0.5) print("Rule 2 - The game will not start until you accutally pick a round from 1-5") time.sleep(0.5) print("Rule 3 - your name can not contain space or numbers") time.sleep(0.5) print("---------------") #Getting both the players names. Also making sure they dont have numbers or spaces in them while True : player1 = str(input("What is player 1's name? ")) if player1.isalpha() == True: time.sleep(0.25) break else: print("That is not an acceptable name please try again") time.sleep(0.25) while True: player2 = str(input("What is player 2's name? ")) if player2.isalpha() == True: print("---------------") time.sleep(0.25) break else: print("That is not an acceptable name please try again") time.sleep(0.25) #checking for int input validation for the amount of rounds in the game while True: try : rounds = int(input("How many rounds do you want to play? 1-5 : ")) print("---------------") time.sleep(0.25) if rounds < 1 or rounds > 5 : print("Please choose a number 1 and 5") time.sleep(0.25) else: break except: print("You didn't even put in the right number how am i supposed to process that bro? ") #Checking if there are anymore rounds to play and if there are then it repeats the loop while rounds > 0 : chips = max_chips #Checking if there are anymore chips left and if there is then it will play the next turn but if not then it will end the round while chips > 0 : print("There are", chips, "chips left") #Gets the amount of chips the player wants to take in there turn num_chips = int(input(f"How many chips does {player1} want to take? 1-3 : ")) if num_chips < 1 or num_chips > 3 : print("please pick a number from 1-3 ") else: chips = chips - num_chips print("You took" ,num_chips, "there are now" ,chips, "left") time.sleep(0.5) #Checks if the turn they just did won them the round and if they did there score gets plus 1 #If they didnt win on that move then they dont get anything and starts the other players turn if chips <= 0 : player1_score = player1_score + 1 print("player 1 score is ", player1_score) print("player 2 score is ", player2_score) print("---------------") time.sleep(0.5) #If the round just finished it take one away from the total rounds because the game stops when the rounds gets to 0 rounds = rounds - 1 print("There are ", rounds, "rounds left") print("---------------") time.sleep(0.5) break #Gets the amount of chips the player wants to take in there turn num_chips = int(input(f"How many chips does {player2} want to take? 1-3 : ")) print("--------------") if num_chips < 1 or num_chips > 3 : print("please pick a number from 1-3 ") else: chips = chips - num_chips print("You took" ,num_chips, "there are now" ,chips, "left") time.sleep(0.5) #Checks if the turn they just did won them the round and if they did there score gets plus 1 #If they didnt win on that move then they dont get anything and starts the other players turn if chips <= 0 : player2_score = player2_score + 1 print("player 1 score is ", player1_score) print("player 2 score is ", player2_score) print("---------------") time.sleep(0.5) #If the round just finished it take one away from the total rounds because the game stops when the rounds gets to 0 rounds = rounds - 1 print("There are ", rounds, "rounds left") print("---------------") time.sleep(0.5) break #Checks who has a higher score after the rounds are finished and then gives the person with the highest score the win. #If the player score is equal it will say they tied if rounds == 0 : print("player 1's score is", player1_score) print("player 2's score is", player2_score) if player1_score > player2_score : print("PLAYER 1 WINS!!!") print("Better luck next time player 2") elif player1_score < player2_score : print("PLAYER 2 WINS!!!") print("Better luck next time player 1") else: print("IT'S A TIE!!!")