Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #===============================================#
- # ///////////////////////////////////////////// #
- # ///////////////////////////////////////////// #
- # ///////////////////////////////////////////// #
- #================= Main Class ==================#
- # About: #
- # This is the main class to my NEA Dice Game. #
- # #
- # Author: #
- # Callum Nicholls #
- # #
- # Date Started: #
- # 29/04/19 #
- #===============================================#
- # ///////////////////////////////////////////// #
- # ///////////////////////////////////////////// #
- # ///////////////////////////////////////////// #
- #============ Importing Libraries ==============#
- import random #
- #===============================================#
- # ///////////////////////////////////////////// #
- # ///////////////////////////////////////////// #
- # ///////////////////////////////////////////// #
- #================== Variables ==================#
- min = 1 #
- max = 6 #
- player1_score = None #
- player2_score = None #
- loop_counter = 5 #
- #===============================================#
- # ///////////////////////////////////////////// #
- # ///////////////////////////////////////////// #
- # ///////////////////////////////////////////// #
- #=============== Player 1 Login ================#
- print("[Player 1] Welcome...")
- player1_welcome = input("[Player 1] Do you have an account? y/n: ")
- if player1_welcome == "n":
- while True:
- player1_username = input("[Player 1] Enter a username: ")
- player1_password = input("[Player 1] Enter a password: ")
- player1_confirmation = input("[Player 1] Confirm password: ")
- if player1_password == player1_confirmation:
- file = open(player1_username+".txt", "w")
- file.write(player1_username+":"+player1_password)
- file.close()
- welcome = "y"
- break
- print("[Player 1] Inputted passwords do not match!")
- if player1_welcome == "y":
- while True:
- player1_login1 = input("[Player 1] Username: ")
- player1_login2 = input("[Player 1] Password: ")
- file = open(player1_login1+".txt", "r")
- player1_data = file.readline()
- file.close()
- if player1_data == player1_login1+":"+player1_login2:
- print("[Player 1] Welcome back, "+player1_login1)
- break
- print("[Player 1] Incorrect username and or password!")
- #===============================================#
- # ///////////////////////////////////////////// #
- # ///////////////////////////////////////////// #
- # ///////////////////////////////////////////// #
- #=============== Player 2 Login ================#
- print("[Player 2] Welcome...")
- player2_welcome = input("[Player 2] Do you have an account? y/n: ")
- if player2_welcome == "n":
- while True:
- player2_username = input("[Player 2] Enter a username: ")
- player2_password = input("[Player 2] Enter a password: ")
- player2_confirmation = input("[Player 2] Confirm password: ")
- if player2_password == player2_confirmation:
- file = open(player2_username+".txt", "w")
- file.write(player2_username+":"+player2_password)
- file.close()
- welcome = "y"
- break
- print("[Player 2] Inputted passwords do not match!")
- if player2_welcome == "y":
- while True:
- player2_login1 = input("[Player 2] Username: ")
- player2_login2 = input("[Player 2] Password: ")
- file = open(player2_login1+".txt", "r")
- player2_data = file.readline()
- file.close()
- if player2_data == player2_login1+":"+player2_login2:
- print("[Player 2] Welcome back, "+player2_login1)
- break
- print("[Player 2] Incorrect username and or password!")
- Menu()
- #===============================================#
- # ///////////////////////////////////////////// #
- # ///////////////////////////////////////////// #
- # ///////////////////////////////////////////// #
- #==================== Menu =====================#
- def Menu():
- selection = int(input("[1]Start Game\n[2]View Leaderboard\n[3]Exit Game\n"))
- if selection == 1:
- dice_roll = "yes"
- while dice_roll == "yes" or dice_roll == "Yes" or dice_roll == "Y" or dice_roll == "y":
- if loop_counter >= 5:
- break
- print("[!] Rolling the dices...")
- print("[!] The dices have been succesfully roled!...")
- print("[!] Player 1's dice has been rolled and landed on the following number...")
- player1_score = print(random.randint(min, max))
- print("[!] Player 2's dice has been rolled and landed on the following number...")
- player2_score = print(random.randint(min, max))
- dice_roll = input("[!] Would you like to roll the dices again? ")
- if selection == 2:
- leaderboard_print()
- if selection == 3:
- exit()
- else:
- print("[!] You have entered an invalid option...")
- #===============================================#
- # ///////////////////////////////////////////// #
- # ///////////////////////////////////////////// #
- # ///////////////////////////////////////////// #
- #================= LeaderBoard =================#
- def leaderboard_print():
- if player1_score > player2_score:
- print("#1 - Player 1 ["+player1_score+"]")
- print("#2 - Player 2 ["+player2_score+"]")
- if player2_score > player1_score:
- print("#1 - Player 2 ["+player2_score+"]")
- print("#2 - Player 1 ["+player1_score+"]")
- if player1_score == player2_score:
- print("[!] Player 1 & Player 2 both have the same score!")
- print("Player 1 ["+player1_score+"]")
- print("Player 2 ["+player2_score+"]")
- Menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement