""" ------------------------------------------------- Project: Take-Away Game Standard: 91883 (AS1.7) v.1 School: Tauranga Boys' College Author: Blaze Smyth Date: THE DATE YOU COMPLETED THE CODE Python: 3.5 ------------------------------------------------- """ import time #Adding time to the text to make it feel more real #Setting the main variables to use for calculations and gameplay Max_chips = 21 Player1_score = 0 Player2_score = 0 Player1_turn = True Chips_left = 0 Chips_taken = 0 explained_game = 0 #Getting all the starting data and introducing the game to the players for the start of the game while True : Player1_name = str(input("What is player one's name? ")) if Player1_name.isalpha() == True: break else: print("\nThat is not a name you fool, try again") while True : time.sleep(0.6) Player2_name = str(input("\nWhat is player two's name? ")) #Asking the player for their name to make the messages more personalised if Player2_name.isalpha() == True: #Checkinng if the name is only letters so the messages have an actual name and not some random numbers break else: print("\nThat is not a name you fool, try again") while True: try: time.sleep(0.6) Rounds = int(input("\nPick the number of rounds you would like to play from 1 to 5 ")) #Asking the player for how many rounds they want to play so they can play the game if Rounds < 1 or Rounds > 5: #Checking if they have put a number between 1 and 5 in so they can play the game print("\nThat is not a number, go back to math class and come back when you can count") else: break except: #Asking again so they can play the game for any number of rounds between 1 and 5 print("\nYou didnt answer at all, please input a number") #Explainig how to play the game so everyone understands how it works while explained_game == 0: time.sleep(1) print("\nHello {} and {} welcome to the pick-up game".format(Player1_name, Player2_name)) time.sleep(2) print("In this game there will be 21 chips to start with, Your goal is to pick up the last chip(s)") time.sleep(2) print("You can choose to pick up 1 to 3 chips a turn and whoevery picks up the last chip(s) wins that round but not the game") time.sleep(2) print("Good luck {} and {}".format(Player1_name, Player2_name)) explained_game =+ 1 break #Starting the game from the first round so you can actually play while Rounds > 0 : Chips_left = Max_chips #Checking the amount of chips to see who won so their score can be tallied while Chips_left > 0 : while True: try: if Player1_turn == True: #making sure both players can play turn by turn for an actual game time.sleep(0.6) print("\nthere are {} chips remaining".format(Chips_left)) time.sleep(0.6) removed_chips = int(input("\nIt is {} turn, pick a number between 1 and 3. ".format(Player1_name))) Player1_turn = not Player1_turn if removed_chips < 1 or removed_chips > 3: print("\npick a number between 1 and 3 you cheater") Player1_turn = True else: Chips_left = Chips_left - removed_chips if Chips_left < 3: #Checking if this turn is the winner so we can add 1 point to their score Player1_score =+ 1 Player1_turn = True time.sleep(0.6) if Rounds > 0: print("\n{} won the round but not the game, {} can still come back".format(Player1_name, Player2_name)) break else: break else: time.sleep(0.6) print("\nthere are {} chips remaining".format(Chips_left)) time.sleep(0.6) removed_chips = int(input("\nIt is {} turn, pick a number between 1 and 3. ".format(Player2_name))) Player1_turn = True #Switching who goes next so its not just a 1 player game if removed_chips < 1 or removed_chips > 3: print("\npick a number between 1 and 3 you cheater") Player1_turn = not Player1_turn else: Chips_left = Chips_left - removed_chips if Chips_left < 3: Player2_score =+ 1 time.sleep(0.6) if Rounds > 0: print("\n{} won the round but not the game, {} can still come back".format(Player2_name, Player1_name)) break else: break except: print("\nplease input a number") #Checking they picked a number so they cant play a 0 round game #Having the ending game sequence so the game doesnt last forever Rounds -= 1 if Player1_score == Player2_score : #Checking the players score to see who won so the players can know time.sleep(0.6) print("\nThe game has ended in a draw! Congratulations!") elif Player1_score < Player2_score : time.sleep(0.6) print("\nHAHA, your a loser {}".format(Player1_name)) else: time.sleep(0.6) print("\nCongrats {}, You have won this game!".format(Player1_name))