Advertisement
Guest User

Untitled

a guest
May 2nd, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.35 KB | None | 0 0
  1. #===============================================#
  2. # ///////////////////////////////////////////// #
  3. # ///////////////////////////////////////////// #
  4. # ///////////////////////////////////////////// #
  5. #================= Main Class ==================#
  6. # About: #
  7. # This is the main class to my NEA Dice Game. #
  8. # #
  9. # Author: #
  10. # Callum Nicholls #
  11. # #
  12. # Date Started: #
  13. # 29/04/19 #
  14. #===============================================#
  15. # ///////////////////////////////////////////// #
  16. # ///////////////////////////////////////////// #
  17. # ///////////////////////////////////////////// #
  18. #============ Importing Libraries ==============#
  19. import random #
  20. #===============================================#
  21. # ///////////////////////////////////////////// #
  22. # ///////////////////////////////////////////// #
  23. # ///////////////////////////////////////////// #
  24. #================== Variables ==================#
  25. min = 1 #
  26. max = 6 #
  27. player1_score = None #
  28. player2_score = None #
  29. loop_counter = 5 #
  30. #===============================================#
  31. # ///////////////////////////////////////////// #
  32. # ///////////////////////////////////////////// #
  33. # ///////////////////////////////////////////// #
  34. #=============== Player 1 Login ================#
  35. print("[Player 1] Welcome...")
  36. player1_welcome = input("[Player 1] Do you have an account? y/n: ")
  37. if player1_welcome == "n":
  38. while True:
  39. player1_username = input("[Player 1] Enter a username: ")
  40. player1_password = input("[Player 1] Enter a password: ")
  41. player1_confirmation = input("[Player 1] Confirm password: ")
  42. if player1_password == player1_confirmation:
  43. file = open(player1_username+".txt", "w")
  44. file.write(player1_username+":"+player1_password)
  45. file.close()
  46. welcome = "y"
  47. break
  48. print("[Player 1] Inputted passwords do not match!")
  49. if player1_welcome == "y":
  50. while True:
  51. player1_login1 = input("[Player 1] Username: ")
  52. player1_login2 = input("[Player 1] Password: ")
  53. file = open(player1_login1+".txt", "r")
  54. player1_data = file.readline()
  55. file.close()
  56. if player1_data == player1_login1+":"+player1_login2:
  57. print("[Player 1] Welcome back, "+player1_login1)
  58. break
  59. print("[Player 1] Incorrect username and or password!")
  60. #===============================================#
  61. # ///////////////////////////////////////////// #
  62. # ///////////////////////////////////////////// #
  63. # ///////////////////////////////////////////// #
  64. #=============== Player 2 Login ================#
  65. print("[Player 2] Welcome...")
  66. player2_welcome = input("[Player 2] Do you have an account? y/n: ")
  67. if player2_welcome == "n":
  68. while True:
  69. player2_username = input("[Player 2] Enter a username: ")
  70. player2_password = input("[Player 2] Enter a password: ")
  71. player2_confirmation = input("[Player 2] Confirm password: ")
  72. if player2_password == player2_confirmation:
  73. file = open(player2_username+".txt", "w")
  74. file.write(player2_username+":"+player2_password)
  75. file.close()
  76. welcome = "y"
  77. break
  78. print("[Player 2] Inputted passwords do not match!")
  79. if player2_welcome == "y":
  80. while True:
  81. player2_login1 = input("[Player 2] Username: ")
  82. player2_login2 = input("[Player 2] Password: ")
  83. file = open(player2_login1+".txt", "r")
  84. player2_data = file.readline()
  85. file.close()
  86. if player2_data == player2_login1+":"+player2_login2:
  87. print("[Player 2] Welcome back, "+player2_login1)
  88. break
  89. print("[Player 2] Incorrect username and or password!")
  90.  
  91. Menu()
  92. #===============================================#
  93. # ///////////////////////////////////////////// #
  94. # ///////////////////////////////////////////// #
  95. # ///////////////////////////////////////////// #
  96. #==================== Menu =====================#
  97. def Menu():
  98. selection = int(input("[1]Start Game\n[2]View Leaderboard\n[3]Exit Game\n"))
  99. if selection == 1:
  100. dice_roll = "yes"
  101. while dice_roll == "yes" or dice_roll == "Yes" or dice_roll == "Y" or dice_roll == "y":
  102. if loop_counter >= 5:
  103. break
  104. print("[!] Rolling the dices...")
  105. print("[!] The dices have been succesfully roled!...")
  106. print("[!] Player 1's dice has been rolled and landed on the following number...")
  107. player1_score = print(random.randint(min, max))
  108. print("[!] Player 2's dice has been rolled and landed on the following number...")
  109. player2_score = print(random.randint(min, max))
  110. dice_roll = input("[!] Would you like to roll the dices again? ")
  111.  
  112. if selection == 2:
  113. leaderboard_print()
  114.  
  115. if selection == 3:
  116. exit()
  117. else:
  118. print("[!] You have entered an invalid option...")
  119. #===============================================#
  120. # ///////////////////////////////////////////// #
  121. # ///////////////////////////////////////////// #
  122. # ///////////////////////////////////////////// #
  123. #================= LeaderBoard =================#
  124. def leaderboard_print():
  125. if player1_score > player2_score:
  126. print("#1 - Player 1 ["+player1_score+"]")
  127. print("#2 - Player 2 ["+player2_score+"]")
  128. if player2_score > player1_score:
  129. print("#1 - Player 2 ["+player2_score+"]")
  130. print("#2 - Player 1 ["+player1_score+"]")
  131. if player1_score == player2_score:
  132. print("[!] Player 1 & Player 2 both have the same score!")
  133. print("Player 1 ["+player1_score+"]")
  134. print("Player 2 ["+player2_score+"]")
  135.  
  136. Menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement