Advertisement
mwmatthew10

Main.py

Dec 12th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.62 KB | None | 0 0
  1. #Programming Project
  2.  
  3. #Main.py
  4. #This file contains the main program of my project. All is made by me from my python programming knowledge unless otherwise stated/referenced.
  5. #Made: 31/10/2018
  6.  
  7. from funcs import * #Imports my funcs module.
  8. import time #Import time to make the rolling have a delay
  9.  
  10. print("Player 1") #Aesthetics prompts player1
  11. success1, player1Name = auth() #Calls for authentication of the player, returns two args: one indicating success, the other the players name
  12. print("Player 2") #Aesthetics prompts player2
  13. success2, player2Name = auth() #Calls for authentication of the player, returns two args: one indicating success, the other the players name
  14.  
  15. def main(player1Name, player2Name): #Defines the main function
  16.     player1 = Player(player1Name, 0) #Initialises a player class and assigns it to player1
  17.     player2 = Player(player2Name, 0) #Initialises a player class and assigns it to player2
  18.     players = [player1, player2] #Creates an array containing the two players
  19.     playerDice = [Dice(), Dice()] #Initialise two dice classes inside of an array for easy access within the loop.
  20.     for q in range(1, 2): #For loop for 5 rounds will count from 1-5
  21.         print("=========================\nRound {0}\n=========================".format(q)) #For aesthetics, formats in the round value.
  22.         for plr in range(1, 3): #For loop for the 2 players, will count 1-2
  23.             rolled = False #So if they do not type roll it will repeat
  24.             while rolled == False: #Repeats until they roll
  25.                 print("\n=========Player {0}=========".format(plr)) #Aesthetics
  26.                 opt = input("\nPlayer {0}: Type roll to roll your dice: ".format(plr)) #Recieves roll input
  27.                 if opt.lower() == "roll": #Checks if they said to roll
  28.                     print("Rolling first dice...") #Aesthetics
  29.                     roll1 = playerDice[plr-1].rollFirst(1, 6) #Calls the rollFirst function of Dice class
  30.                     time.sleep(1.5) #Yield for 1.5 seconds to "roll" dice
  31.                     print("You rolled a {0}\n".format(roll1)) #States what the player rolled. Formats in the roll value
  32.                    
  33.                     print("Rolling second dice...")#Aesthetics
  34.                     roll2 = playerDice[plr-1].rollSecond(1, 6) #Calls the rollSecond function of the Dice class
  35.                     time.sleep(1.5) #Yield for 1.5 seconds to "roll" dice
  36.                     print("You rolled a {0}\n".format(roll2)) #States what the player rolled. Formats in the roll value
  37.                    
  38.                     score = calculateScore(roll1, roll2) #Calculates the score, doing both even and odd and calling for a second roll if necessary
  39.                    
  40.                     players[plr-1].incrementScore(score) #Increments the players score by score
  41.                     print("\nYou scored: {0} Points!\nYour score is now: {1}\n".format(score, players[plr-1].Score)) #Aesthetics
  42.                     rolled = True #Sets rolled to true so it knows to loop
  43.        
  44.         winner = player1.Score > player2.Score and player1 or player2 #Decides who's the player using comparisons
  45.         loser = player1.Score < player2.Score and player1 or player2 #Decides who's the loser using comparisons
  46.         if player1.Score != player2.Score:
  47.             #Aesthetics
  48.             print("=======Game Over!=======\n")
  49.             print("=== {0} is the winner! ===\nThey scored: {1} Points!".format(winner.Name, winner.Score))
  50.             print("\n=== {0} is the loser! :( ===\nThey managed to score: {1} Points though!\n".format(loser.Name, loser.Score))
  51.             print("===Leaderboard===")
  52.             #End of aesthetics
  53.         else:
  54.             winner, loser = tieBreaker([player1, player2], playerDice) #Calls tiebreaker to finish the game
  55.             #Aesthetics
  56.             print("=======Game Over!=======\n")
  57.             print("=== {0} is the winner! ===\nThey scored: {1} Points!".format(winner.Name, winner.Score))
  58.             print("\n=== {0} is the loser! :( ===\nThey managed to score: {1} Points though!\n".format(loser.Name, loser.Score))
  59.             print("===Leaderboard===")
  60.             #End of aesthetics
  61.         setLeaderboard(winner, loser) #Sets and displays leaderboard
  62.        
  63.        
  64.        
  65. #Check if login was successful
  66. if success1 and success2:
  67.     print("player1 Auth: {0} \nPlayer2 Auth: {1}".format(success1, success2)) #Print authentication status
  68.     main(player1Name, player2Name) #Initialise program if authorisation is successful
  69. else:
  70.     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