# #------------------------------------------------------# # |Name : The Take-Away Game | # |Purpose : 11DGT | # |Author: Lincoln | # |Created : Monday 25th of March 2024 | # |Copyright : © Lincoln 8/03/2024 | # #------------------------------------------------------# #Imports import time #Constants MAX_CHIPS = 21 #Variables total_chips = MAX_CHIPS player1_score = 0 player2_score = 0 #Inputs chips_taken = int number_of_rounds = int name1 =str name2 = str rule = str #Easier reading def spacing() : print() #Cooler looking text def message(message1, delay=0.05): spacing() for char in message1: print(char, end='', flush=True) time.sleep(delay) def main_script () : global MAX_CHIPS global player1_score global player2_score message1 = "Welcome to the Take-Away game" message(message1) time.sleep(0.5) spacing() message1 = "What is player 1's name" message(message1) name1 = str(input(": ")) message1 = "What is player 2's name" message(message1) name2 = str(input(": ")) message1 = "Do you want to hear the rules? (y/n)" message(message1) rule = str(input(": ")) if rule == "y" : rules() message1 = "How many rounds do you want to play?" message(message1) number_of_rounds = int(input(": ")) #Loop while number_of_rounds >= 0 : total_chips = MAX_CHIPS while total_chips >= 0 : #Player 1's turn spacing() message1 = "It is {}'s turn" .format(name1) message(message1) time.sleep(1) spacing() message1 = "How many chips does {} want to take? (1, 2 or 3)" .format(name1) message(message1) chips_taken = int(input(": ")) #Checking if player took the right amount of chips if chips_taken > 3 : message1 = "You can only take 1, 2 or 3 chips from the pile" message(message1) time.sleep(1) spacing() message1 = "Chose again" message(message1) chips_taken = int(input(": ")) #Checking if player took the right amount of chips if chips_taken <= 0 : message1 = "You can only take 1, 2 or 3 chips from the pile" message(message1) time.sleep(1) spacing() message1 = "Chose again" message(message1) chips_taken = int(input(": ")) total_chips = total_chips - chips_taken message1 = "{} has taken {} chips" .format(name1,chips_taken) message(message1) time.sleep(1) if total_chips > 0 : spacing() message1 = "There are {} chips remaining" .format(total_chips) message(message1) time.sleep(1) #Checking if player won the round elif total_chips <= 0 : spacing() message1 = "There are no more chips remaining" message(message1) time.sleep(1) spacing() message1 = "{} has won this round".format(name1) message(message1) time.sleep(1) total_chips = MAX_CHIPS player1_score = player1_score + 1 number_of_rounds = number_of_rounds - 1 #checking who won overall if number_of_rounds == 0 : if player1_score > player2_score : spacing() message1 = "{} has won the game." .format(name1) message(message1) spacing() quit() if player2_score > player1_score : spacing() message1 = "{} has won the game." .format(name2) message(message1) spacing() quit() elif player1_score == player2_score : spacing() message1 = "Both players had a score of {} so it was a draw" .format(player1_score) message(message1) spacing() quit() #Player 2's turn spacing() message1 = "It is {}'s turn" .format(name2) message(message1) time.sleep(1) spacing() message1 = "How many chips does {} want to take? (1, 2 or 3)" .format(name2) message(message1) chips_taken = int(input(": ")) #Checking if player took the right amount of chips if chips_taken > 3 : message1 = "You can only take 1, 2 or 3 chips from the pile" message(message1) time.sleep(1) spacing() message1 = "Chose again" message(message1) chips_taken = int(input(": ")) #Checking if player took the right amount of chips if chips_taken <= 0 : message1 = "You can only take 1, 2 or 3 chips from the pile" message(message1) time.sleep(1) spacing() message1 = "Chose again" message(message1) chips_taken = int(input(": ")) total_chips = total_chips - chips_taken message1 = "{} has taken {} chips" .format(name2,chips_taken) message(message1) time.sleep(1) if total_chips > 0 : spacing() message1 = "There are {} chips remaining" .format(total_chips) message(message1) time.sleep(1) #Checking if player won the round elif total_chips <= 0 : spacing() message1 = "There are no more chips remaining" message(message1) time.sleep(1) spacing() message1 = "{} has won this round".format(name2) message(message1) time.sleep(1) total_chips = MAX_CHIPS player2_score = player2_score + 1 number_of_rounds = number_of_rounds - 1 #Checking who won if number_of_rounds == 0 : if player1_score > player2_score : spacing() message1 = "{} has won the game" .format(name1) message(message1) spacing() quit() if player2_score > player1_score : spacing() message1 = "{} has won the game." .format(name2) message(message1) spacing() quit() elif player1_score == player2_score : spacing() message1 = "Both players had a score of {} so it was a draw" .format(player1_score) message(message1) spacing() quit() def rules () : message1 = "There are 21 chips" message(message1) time.sleep(0.8) spacing() message1 = "You can take up to 3 chips per turn" message(message1) time.sleep(1) spacing() message1 = "Get the last chip to win" message(message1) time.sleep (1) spacing() message1 = "Whoever wins the most rounds wins" message(message1) time.sleep(1) spacing() main_script()