""" ------------------------------------------------- Project: Take-Away Game Standard: 91883 (AS1.7) v.1 School: Tauranga Boys' College Author: Luke Whitney Date: THE DATE YOU COMPLETED THE CODE Python: 3.5 ------------------------------------------------- """ #Imports import time #Variables Max_chips = 21 player_1_score = 0 player_2_score = 0 chips_taken = 0 chips_left = 0 """ ------------------------------------------------ """ #Player 1's name player_1_name = input ("Player 1's name goes here (no numbers or special characters): ") #Player 2's name player_2_name = input ("Player 2's name goes here (no numbers or special characters): ") #Amount of rounds desired round_amount = input ("How many rounds would you like to play (only numbers please)? ") #Making sure inputs are desired outcome player_1 = player_1_name.isalpha () player_2 = player_2_name.isalpha () round = round_amount.isnumeric () """ ------------------------------------------------ """ #Saying Hello, and Making Sure Their Name is a String #This will repeat until player one changes the name to only letters while player_1 == False or True: if player_1 == False: print ("No special characters or letters please player 1") player_1_name = input ("Player 1's name goes here (no numbers or special characters): ") player_1 = player_1_name.isalpha () else: print ("Hello, {}. Welcome to the counting down game.".format (player_1_name)) break #This will repeat until player two change the name to only letters while player_2 == False or True: if player_2 == False: print ("No special characters or letters please player 2") player_2_name = input ("Player 2's name goes here (no numbers or special characters): ") player_2 = player_2_name.isalpha () else: print ("Hello, {}. Welcome to the counting down game.".format (player_2_name)) break #This will repeat until they change the round amount to an integer while round == False or True: if round == False: print ("Please input only numbers under round amount") round_amount = input ("How many rounds would you like to play (only numbers please)? ") round = round_amount.isnumeric () else: break """ ------------------------------------------------- """ #Rules & introduction print ("Hello, and welcome to the take-away game. The aim of the game is to be the first person to end on 0 chips.") time.sleep (2.5) print ("Each round the players will take turns taking either 1, 2 or 3 chips per turn. There are 21 chips each round, and if you pull the last chips you win.") time.sleep (3) print ("Each time you decide to play, you will be asked the amount of rounds you would like to play, and whoever wins the most rounds wins the game.") time.sleep (3) print ("Ready, set, begin!") """ ------------------------------------------------- """ #loop to make sure game continues after round def take_chips(player_name): while True: chips_taken = input("{}, How many chips would you like to take? ".format(player_name)) if chips_taken.isdigit() and 1 <= int(chips_taken) <= 3: return int(chips_taken) else: print("Please pick a suitable number between 1 and 3.") for round_num in range(1, round + 1): print("Round {}:".format(round_num)) chips_left = Max_chips while chips_left > 0: print("There are {} chips left.".format(chips_left)) chips_taken = take_chips(player_1_name) chips_left -= chips_taken if chips_left <= 0: player_1_score += 1 break print("There are {} chips left.".format(chips_left)) chips_taken = take_chips(player_2_name) chips_left -= chips_taken if chips_left <= 0: player_2_score += 1 break print("\nGame Over!") print("Final Score - {}: {}, {}: {}".format(player_1_name,player_1_score,player_2_name,player_1_score)) if player_1_score > player_2_score: print("{} wins!".format(player_1_name)) elif player_2_score > player_1_score: print("{} wins!".format(player_2_name)) else: print("It's a tie!")