""" ------------------------------------------------- Project: Take-Away Game Standard: 91883 (AS1.7) v.1 School: Tauranga Boys' College Author: Mac Gillingham Date: THE DATE YOU COMPLETED THE CODE Python: 3.5 ------------------------------------------------- """ # Importing libraries import random import time # Constant variables chips_max = 21 player1_score = 0 player2_score = 0 chips_remaining = 0 chips_taken = 0 def chips(): print("There are currently {} chips.".format(chips_remaining)) print("(c) " * chips_remaining) # Intro print() print(" _ _ ") print(" (_) | | ") print(" _ __ _ ___| | ___ _ _ __ __ _ __ _ _ __ ___ ___ _ __ _ _ ") print(" | '_ \| |/ __| |/ / | | | '_ \ / _` |/ _` | '_ ` _ \ / _ \ | '_ \| | | |") print(" | |_) | | (__| <| |_| | |_) | (_| | (_| | | | | | | __/_| |_) | |_| |") print(" | .__/|_|\___|_|\_\__,_.| .__/ \__, |\__,_|_| |_| |_|\___(_) .__/ \__, |") print(" | | | | __/ | | | __/ |") print(" |_| |_| |___/ |_| |___/ ") print() print() print("type 'help' to learn how to play.") print("type anything else to skip.") help_ans = input() if str.lower(help_ans) == "help": # Checking if the player knows how to play print() print("-=< HOW TO PLAY >=-") print("You and another player will take turns removing up to 3 chips from the pile.") print("the goal of the game is to take the last chip.") print("Whichever player has won the most rounds by the end of the game wins!") if str.lower(help_ans) == "anything else": print() print("ok funny guy") print() print() # Player naming while True: print("Player 1, please enter your name.") p1_name = str(input()) if p1_name.isalpha() == True: # Checking name validity break else: print("that name aint allowed mate") # nice while True: print("Player 2, please enter your name.") p2_name = str(input()) if p1_name.isalpha() == True: # Checking name validity break else: print("that name aint allowed mate") # Game setup while True: try: print("How many rounds would you like to play?") print("Choose from 1-5.") rounds = int(input()) if rounds < 1 or rounds > 5: print("what part of 'choose from 1-5' do you not understand?") else: break except: print("You didn't even input a number how am i supposed to process that you bro?") while rounds > 0: chips_remaining = chips_max print() if rounds == 1: print("-=< FINAL ROUND >=-") else: print("Rounds left: {}".format(rounds)) time.sleep(1) # Gameplay loop while chips_remaining > 0: # Player 1 turn print() chips() print() print("{}'s turn.".format(p1_name)) while True: try: # Denying invalid inputs print("How many chips would you like to take?") chips_taken = int(input()) if chips_taken < 1 or chips_taken > 3: print("nuh uh") else: break except: print("You didn't even input a number how am i supposed to process that you bro?") chips_remaining = chips_remaining - chips_taken if chips_remaining < 1: # Checking if p1 has won print() print("Round over") print("{} gets a point!".format(p1_name)) player1_score = player1_score + 1 print("-------------------------------------------") break # Player 2 turn print() chips() print() print("{}'s turn.".format(p2_name)) while True: try: # Denying invalid inputs print("How many chips would you like to take?") chips_taken = int(input()) if chips_taken < 1 or chips_taken > 3: print("nuh uh") else: break except: print("You didn't even input a number how am i supposed to process that you bro?") chips_remaining = chips_remaining - chips_taken if chips_remaining < 1: # Checking if p2 has won print() print("Round over") print("{} gets a point!".format(p2_name)) player2_score = player2_score + 1 print("-------------------------------------------") break # End of round time.sleep(0.5) if rounds > 1: print() print("Scores:") print("{}: {}".format(p1_name, player1_score)) print("{}: {}".format(p2_name, player2_score)) rounds = rounds - 1 # End of game while True: if rounds == 0: print() print("Game over.") print("{}'s final score: {}".format(p1_name, player1_score)) print("{}'s final score: {}".format(p2_name, player2_score)) if player1_score > player2_score: print("{} wins!".format(p1_name)) if player1_score < player2_score: print("{} wins!".format(p2_name)) if player1_score == player2_score: print("Tie!") break