Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Programming Project
- #Main.py
- #This file contains the main program of my project. All is made by me from my python programming knowledge unless otherwise stated/referenced.
- #Made: 31/10/2018
- from funcs import * #Imports my funcs module.
- import time #Import time to make the rolling have a delay
- print("Player 1") #Aesthetics prompts player1
- success1, player1Name = auth() #Calls for authentication of the player, returns two args: one indicating success, the other the players name
- print("Player 2") #Aesthetics prompts player2
- success2, player2Name = auth() #Calls for authentication of the player, returns two args: one indicating success, the other the players name
- def main(player1Name, player2Name): #Defines the main function
- player1 = Player(player1Name, 0) #Initialises a player class and assigns it to player1
- player2 = Player(player2Name, 0) #Initialises a player class and assigns it to player2
- players = [player1, player2] #Creates an array containing the two players
- playerDice = [Dice(), Dice()] #Initialise two dice classes inside of an array for easy access within the loop.
- for q in range(1, 2): #For loop for 5 rounds will count from 1-5
- print("=========================\nRound {0}\n=========================".format(q)) #For aesthetics, formats in the round value.
- for plr in range(1, 3): #For loop for the 2 players, will count 1-2
- rolled = False #So if they do not type roll it will repeat
- while rolled == False: #Repeats until they roll
- print("\n=========Player {0}=========".format(plr)) #Aesthetics
- opt = input("\nPlayer {0}: Type roll to roll your dice: ".format(plr)) #Recieves roll input
- if opt.lower() == "roll": #Checks if they said to roll
- print("Rolling first dice...") #Aesthetics
- roll1 = playerDice[plr-1].rollFirst(1, 6) #Calls the rollFirst function of Dice class
- time.sleep(1.5) #Yield for 1.5 seconds to "roll" dice
- print("You rolled a {0}\n".format(roll1)) #States what the player rolled. Formats in the roll value
- print("Rolling second dice...")#Aesthetics
- roll2 = playerDice[plr-1].rollSecond(1, 6) #Calls the rollSecond function of the Dice class
- time.sleep(1.5) #Yield for 1.5 seconds to "roll" dice
- print("You rolled a {0}\n".format(roll2)) #States what the player rolled. Formats in the roll value
- score = calculateScore(roll1, roll2) #Calculates the score, doing both even and odd and calling for a second roll if necessary
- players[plr-1].incrementScore(score) #Increments the players score by score
- print("\nYou scored: {0} Points!\nYour score is now: {1}\n".format(score, players[plr-1].Score)) #Aesthetics
- rolled = True #Sets rolled to true so it knows to loop
- winner = player1.Score > player2.Score and player1 or player2 #Decides who's the player using comparisons
- loser = player1.Score < player2.Score and player1 or player2 #Decides who's the loser using comparisons
- if player1.Score != player2.Score:
- #Aesthetics
- print("=======Game Over!=======\n")
- print("=== {0} is the winner! ===\nThey scored: {1} Points!".format(winner.Name, winner.Score))
- print("\n=== {0} is the loser! :( ===\nThey managed to score: {1} Points though!\n".format(loser.Name, loser.Score))
- print("===Leaderboard===")
- #End of aesthetics
- else:
- winner, loser = tieBreaker([player1, player2], playerDice) #Calls tiebreaker to finish the game
- #Aesthetics
- print("=======Game Over!=======\n")
- print("=== {0} is the winner! ===\nThey scored: {1} Points!".format(winner.Name, winner.Score))
- print("\n=== {0} is the loser! :( ===\nThey managed to score: {1} Points though!\n".format(loser.Name, loser.Score))
- print("===Leaderboard===")
- #End of aesthetics
- setLeaderboard(winner, loser) #Sets and displays leaderboard
- #Check if login was successful
- if success1 and success2:
- print("player1 Auth: {0} \nPlayer2 Auth: {1}".format(success1, success2)) #Print authentication status
- main(player1Name, player2Name) #Initialise program if authorisation is successful
- else:
- print("player1 Auth: {0} \nPlayer2 Auth: {1}".format(success1, success2)) #Print who failed to authenticate if not successful
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement