#------------------------------------------------------------ #Project : Take-Away Game #standard : 91883 (As1.7) v.1 #School : Tauranga Boy's College #Author : Shevon Julian Joseph #Date : 26/03/2024 #Python : 3.5 #------------------------------------------------------------ import time #-------------------------------------------------------------------- def main(): print("----Welcome to Take Away Game----") print() #Asking player 1's name and checking if it is valid. If it is invalid asking player 1 to enter a valid name. while True: player1_name = input(" What is your name player 1? ") if player1_name.isalpha() == True : break else: print() print(" Your name is not valid Player 1, try again!") print() #Asking player 2's name and checking if it is valid. If it is invalid asking player 2 to enter a valid name. while True: player2_name = input(" What is your name player 2? ") if player2_name.isalpha() == True : break else: print() print(" Your name is not valid Player 2, try again!") #Introducing the game to the players. print() print(" IT's {} VS {} ".format( player1_name,player2_name) ) time.sleep(2) print() print("------------Game Rules------------") print() time.sleep(2) print() print(" + Pick number of rounds you both wish to play.") time.sleep(2) print(" + You both have only 21 chips.") time.sleep(2) print(" + You can only pick chips between 1 and 3. ") time.sleep(2) print(" + The player who picks the last chip wins the round.") time.sleep(2) print() print("-----------GAME BEGINS-----------") print() time.sleep(3) #Asking the number of rounds player's would like to play. num_rounds = int(input("How many rounds do you want to play? ")) #Making the player's score 0 player1_score = 0 player2_score = 0 #Main game loop. for round_num in range(1, num_rounds + 1): chips_remaining = 21 print(f"\nRound {round_num}: ", " | ",player1_name," : ",player1_score , " | ",player2_name," : ", player2_score) #Each player's turn the loop show the number of chips remaining. while chips_remaining > 0 : print(f"\nChips Remaining : {chips_remaining}") #player 1's turn. print(f"\n{player1_name}'s turn : ") while True: player1_choice = int(input("How many chips do you want to take? (1,2, or 3) : ")) if 1 <= player1_choice <= min(3, chips_remaining):#Ensuring the player can only pick 1, and remianing chips. break elif player1_choice > 3: print(" ! please enter a number between 1 and 3. ") else: print(" ! please enter a number between 1 and ",chips_remaining ) chips_remaining = chips_remaining - player1_choice #player 1's score adding if chips_remaining <=0 : print(f"\nCongratulations {player1_name} wins this round! ") print() player1_score += 1 break #palyer 2's turn. print(f"\n{player2_name}'s turn : ") while True: player2_choice = int(input("How many chips do you want to take?(1,2, or 3) : ")) if 1<= player2_choice <= min(3, chips_remaining):#Ensuring the player can only pick 1, and remianing chips. break elif player2_choice > 3: print(" ! please enter a number between 1 and 3. ") else: print(" ! please enter a number between 1 and ",chips_remaining ) chips_remaining = chips_remaining - player2_choice #player 2's score adding if chips_remaining <= 0 : print(f"\nCongratulations {player2_name} wins this round! ") player2_score += 1 break #End of the game. print("\n----------Game over----------") print() print(f"\nFinal Scores : {player1_name} : {player1_score} | {player2_name} : {player2_score} ") print() if player1_score > player2_score : print(f"{player1_name} wins the game! ") print() elif player2_score > player1_score : print(f"{player2_name} wins the game! ") print() else: print("It's a Tie!") print() print("-----THANK YOU FOR PLAYING MY GAME-----") main()