#-------------------------------------------------------------------------- # Name : Pick Up Game # Purpose : 11DGT # Author: Rhys mason # Created : 22/03/2024 # Copyright : ©Rhys Mason 22/03/2024 #-------------------------------------------------------------------------- #the max chips veriable is for at the begining of every round it sets the remaining chips back to 21 Max_chips = 21 #player1_score is to keep track of player 1's score to compare it to player 2's score and print it player1_score = 0 #player2_score is just like player1_score exept it tracks player 2's score player2_score = 0 #the chips_remaining veriable is used to keep track of the remaining chips for the game and if it drops below 1 the code will know that that is the end of the game chips_remaining = 0 #roundp is a veriable i made for printing(p) the round number roundp = 0 #input and validation for player 1's name. if the input isint just letter it will make you retry while True: name1 = str(input("player 1 name: ")) if name1.isalpha() == True: break else: print("that is not a acceptable name please try again") #input and validation for player 2's name. if the input isint letters it will make you retry while True: name2 = str(input("player 2 name: ")) if name2.isalpha() == True: break else: print("that is not a acceptable name please try again") #this code lets you input a number for the amount of rounds but if the user dosint input a number or it isnt between 1 - 5 you will have to try again while True: try: rounds = int(input("how meny rounds do you want to play? 1 - 5: ")) if rounds < 1 or rounds > 5: print("A NUMBER BETWEEN 1 - 5!") else: break except: print("NUMBER, A NUMBER. WAS THAT A NUMBER?") #while there are still unplated rounds this will keep replaying everything inside it while rounds > 0: #this makes it so at the end of every round the chips go back to 21 print(" ") roundp = roundp + 1 print("round ",roundp," fight!") chips_remaining = Max_chips #this makes it so while chips_remaining > 0: #this code prints the amount for chips remaning print(" ") print("there are ", chips_remaining," chips left") #this loop of code asks player 1 for how meny chips he wants to take (1-3) and deducts it from the remaning_chips veriable. if the unput that player 1 put in isint between 1 - 3 or isint a number at all he will have to input a new number to use insted between 1 - 3 print(name1,", it is your tern" ) while True: try: deduct = int(input("how meny chips do you want to take? 1 - 3: ")) if deduct < 1 or deduct > 3: print("A NUMBER BETWEEN 1 - 3!") else: chips_remaining = chips_remaining - deduct if chips_remaining < 1: #this code checks to see if player 1 has won the round and if he has it adds 1 to the score and stops the round from reacuring but if he hasint it continue's as normal player1_score = player1_score + 1 rounds = rounds - 1 break break break except: print("NUMBER, A NUMBER. WAS THAT A NUMBER?") print(" ") #this code is to check if after player 1 takes his chips if their are any left and if their isint the round ends if chips_remaining < 1: print("round finished", name1," took won 1 point") print(" ") break print("there are ", chips_remaining," chips left") #this loop asks player 2 to take chips off of the pile from 1 to 3 and checks if it is valid,prity much the same as the loop ubove but im not sure how to make them 1 loop print(name2,", it is your tern" ) while True: try: deduct = int(input("how meny chips do you want to take? 1 - 3: ")) if deduct < 1 or deduct > 3: print("A NUMBER BETWEEN 1 - 3!") else: #this checks to see if after he has deducted his chips if he has won and if player 2 has it adds 1 point to his score and brakes the round loop chips_remaining = chips_remaining - deduct if chips_remaining < 1: player2_score = player2_score + 1 rounds = rounds - 1 break break except: print("NUMBER, A NUMBER. WAS THAT A NUMBER?") print(" ") #this code is to check if after player 2 takes his chips if their are any left and if their isint the round ends if chips_remaining < 1: print("round finished", name2," took won 1 point") print(" ") break #this code plays when the game finishes and checks to see who won, then congratulates them if player1_score > player2_score: print(name1," wins with ", player1_score, ", congrats!!!") if player2_score > player1_score: print(name2," wins with ", player2_score, ", congrats!!!") if player1_score == player2_score: print(name1," and ",name2," you tied with a score of ", player1_score, ", unlucky :(")