# ------------------------------------------------- # Project: Take-Away Game # Standard: 91883 (AS1.7) v.1 # School: Tauranga Boys' College # Author: Mannix # Date: THE DATE YOU COMPLETED THE CODE # Python: 3.5 # ------------------------------------------------- # imports a time feature so I can add breaks inbetween each line of context import time player1_score = 0 player2_score = 0 MAXCHIPS = 21 chipsLeft = 0 print("▀▀█▀▀ █▀▀█ █░█ █▀▀   █▀▀█ █░░░█ █▀▀█ █░░█   █▀▀▀ █▀▀█ █▀▄▀█ █▀▀") print("░▒█░░ █▄▄█ █▀▄ █▀▀   █▄▄█ █▄█▄█ █▄▄█ █▄▄█   █░▀█ █▄▄█ █░▀░█ █▀▀") print("░▒█░░ ▀░░▀ ▀░▀ ▀▀▀   ▀░░▀ ░▀░▀░ ▀░░▀ ▄▄▄█   ▀▀▀▀ ▀░░▀ ▀░░░▀ ▀▀▀") # Asking for players name without numbers or spaces and if player enters number or space it will continue to ask while True: player1_name = str(input("What is your name Player 1? ")) if player1_name.isalpha() == True: break else: print("Please re-enter your name the last one just wont work") # Asking for players namer without numbers or spaces and if player enters number or space it will continue to ask while True: player2_name = str(input("What is your name PLayer 2? ")) if player2_name.isalpha() == True: break else: print("Please re-enter your name the last one just wont work") # Asking player how many rounds they would like to play 1-5 if they choose a number less than 1 or more than 5 it will continue to ask while True : try: round_num = int(input("How many rounds do you want to play ? 1-5: ")) if round_num <1 or round_num >5: print("please input a number 1-5: ") else: break except: print("You didn't even put in a number? PUT IN A NUMBER !!!") #Stating the number of rounds left and chips while round_num > 0: chipsLeft = MAXCHIPS print() print(f"There are {round_num} rounds left.") time.sleep(2) print() print(f"There are {chipsLeft} chips left.") print() # Player 1 Turn while chipsLeft > 0: player_choice = int(input(f"{player1_name} how many chips would you like to take?: ")) if player_choice < 1 or player_choice > 3 : print("YOU CAN'T DO THAT") else: chipsLeft = chipsLeft - player_choice print() print(f"there are {chipsLeft} chips left") print("------------------------------------") # If there are no more chips to take the player that took it wins if chipsLeft < 1: print(f"{player1_name} wins this round!") player1_score = player1_score + 1 print(f"The current score is {player1_score}-{player2_score}") print("-------------------------------------------------------") round_num -=1 break # Player 2 turn player_choice = int(input(f"{player2_name} how many chips would you like to take?: ")) if player_choice < 1 or player_choice > 3 : print("YOU CAN'T DO THAT") else: chipsLeft = chipsLeft - player_choice print() print(f"there are {chipsLeft} chips left") print("------------------------------------") # If there are no more chips to take the player that took the last chip wins that round if chipsLeft <1: print(f"{player2_name} wins this round!") print() player2_score = player2_score + 1 print(f"The current score is {player1_score}-{player2_score}") print("-------------------------------------------------------") round_num -=1 break # Once round_num = 0 they means the game has finished and the score will be presented and who has won name will be presented if round_num == 0: print(f"The game has finished with the final score being {player1_score}-{player2_score}") if player1_score > player2_score: print(f"{player1_name} has won") elif player2_score > player1_score: print(f"{player2_name} has won") else: print("It has ended in a draw! ")