#------------------------------------------------- # Project: Pick Up Game # Standard: 91883 # School: Tauranga Boys' College # Author: Hayden De Rohan # Date: 22/03/23 #------------------------------------------- # Imports import time # Variables Rounds = int Player_1, Player_1_Score = str, 0 Player_2, Player_2_Score = str, 0 Players = [] Chips = 21 #Constants MAX_ROUNDS = 7 # FUCNTIONS #function for the Rules to make the main function look cleaner def Rules() : print("READ IF IT'S YOUR FIRST TIME PLAYING ELSE JUST INGORE") print("Players take turns taking 1-3 chips from a pool of 21") print("The goal is to take the last remaining token to gain a point") print("The player with the most points by the end of your set amount of rounds wins overall - rounds can be 1-7") print("Good luck") #Displays chips remainng, making this a function makes it easy to access def ChipsLeft() : global Chips if Chips < 0 : fade_in_print("There is [0] chips remaining") else : fade_in_print("There is [{}] chips remaining".format(Chips)) # Asks for a input by player 1 and validates saves name input as a variable "Player_1" def NamingPlayer1() : while True : SmallSpacing() Player_Name = str(input("What is Player 1's name? -- ")) if Player_Name.isalpha() == True : global Player_1 Player_1 = Player_Name Players.append(Player_1) SmallSpacing() fade_in_print("Player 1's name is [{}]".format(Player_1)) break else : SmallSpacing() fade_in_print("Plase try a name without spacing or numbers") # Asks for a input by player 2 and validates saves name input as a variable "Player_2' #I've split the naming of players into 2 parts because I wasn't able to figure out a way to merge the two together def NamingPlayer2() : while True : SmallSpacing() Player_Name = str(input("What is Player 2's name? -- ")) if Player_Name.isalpha() == True : global Player_2 Player_2 = Player_Name Players.append(Player_2) SmallSpacing() fade_in_print("Player 2's name is [{}]".format(Player_2)) break else : SmallSpacing() fade_in_print("Plase try a name without spacing or numbers") # Asks players for how many rounds with validation def NumRounds() : while True : try : SmallSpacing() RequestedRounds = int(input("How many rounds do you wish to play? -- ")) if RequestedRounds < 1 or RequestedRounds > MAX_ROUNDS : fade_in_print("A number between 1 and 7 games will be too long otherwise") else : global Rounds Rounds = RequestedRounds SmallSpacing() fade_in_print("You'll be playing {} rounds".format(Rounds)) break except : fade_in_print("Try an integer rather than what you did") #Displays the players current scores making this a function makes for easy access def Scores() : SmallSpacing() print("[{}] has a score of ".format(Player_1), Player_1_Score) print("[{}] has a score of ".format(Player_2), Player_2_Score) SmallSpacing() #The merged version of the previous two functions for handling player turns handled in one function def player_turn(player_name): global Chips SmallSpacing() fade_in_print("It's {}'s turn".format(player_name)) while True : try: SmallSpacing() ChipsTaken = int(input("How many chips will you take? [1,2,3] -- ")) if ChipsTaken < 1 or ChipsTaken > 3: SmallSpacing() fade_in_print("1,2 or 3 bud") else: SmallSpacing() Chips -= ChipsTaken break except: SmallSpacing() fade_in_print("Try an integer") # Quick access for time.sleep() def Sleep() : time.sleep(0.75) # Makes text look nicer def fade_in_print(text, delay=0.01875): for i in range(len(text)): print(text[i], end='', flush=True) time.sleep(delay) print() # Makes blank spaces for better looks def SmallSpacing() : print() # Calls all main import functions and puts the main game in a small loop for visual clarity def MainFunc() : global Player_1_Score global Player_2_Score Rules() NamingPlayer1() NamingPlayer2() NumRounds() # Loop main functions in rounds for i in range(0, (Rounds)): print(i) global Chips Chips = 3 Scores() Sleep() ChipsLeft() Sleep() while Chips > 0: # Cycle between the two players for player in Players: #print("Round = ", i) player_turn(player) Sleep() ChipsLeft() Sleep() if Chips <= 0: if player == Player_1: Player_1_Score += 1 else: Player_2_Score += 1 SmallSpacing() fade_in_print("{} has won and they get a point".format(player)) Sleep() if (i) <= Rounds: fade_in_print("Starting round [{}]".format(i + 1)) SmallSpacing() else: break # Exit the while loop and continue to the next round if Chips <= 0: break # Exit the while loop and continue to the next round SmallSpacing() print("- Final Scores -") Sleep() Scores() # Calls the main function if __name__ == "__main__" : SmallSpacing() fade_in_print(" -- Game Worked :D -- ") SmallSpacing() MainFunc() else : fade_in_print("Some funky error happened relaunch the program :D")