Advertisement
Guest User

Untitled

a guest
Oct 1st, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.67 KB | None | 0 0
  1. """CSV is used for the login system. Random / Randint is used for the dice"""
  2. import csv
  3. from random import randint
  4.  
  5. #########################################################################################
  6. # Authenticator #
  7. #########################################################################################
  8.  
  9. def importCredentials():
  10. """Read the user's usernames & password in the csv file"""
  11. with open ('Credentials.csv', 'r') as myFile:
  12. reader = csv.reader(myFile)
  13. Credentials = list(reader)
  14. return Credentials
  15.  
  16. def userLogin():
  17. """Get useranme & password"""
  18. print("Player 1, please enter your credentials")
  19. print("")
  20. username = input("Please enter your username: ")
  21. password = input ("Please enter your password: ")
  22. print("")
  23. print("Player 2, please enter your credentials")
  24. print("")
  25. username2 = input("Please enter your username: ")
  26. password2 = input ("Please enter your password: ")
  27. return username, password, username2, password2
  28.  
  29. def searchList(uname, pword, uname2, pword2, clist):
  30. """ valid is set to false by default"""
  31. valid = False
  32. player1 = False
  33. player2 = False
  34. """Get uname and pword from range with in clist"""
  35. for x in range (0, len(clist)):
  36. if uname == clist[x][0]:
  37. if pword == clist[x][1]:
  38. player1 = True
  39. if uname2 == clist[x][0]:
  40. if pword2 == clist[x][1]:
  41. player2 = True
  42. if player1 == True and player2 == True:
  43. valid = True
  44. break
  45. else:
  46. valid = False
  47.  
  48. return valid
  49. """Instead of having two for loops used IF statements"""
  50. # for i in range (0, len(clist)):
  51. # if uname2 == clist[i][0]:
  52. # if pword2 == clist[i][1]:
  53. # valid = True
  54. # break
  55. # else:
  56. # valid = False
  57. # return valid
  58.  
  59. def main():
  60. """Outputs x onto python shell"""
  61. Credentials = importCredentials()
  62. """Get username and password"""
  63. username, password, username2, password2 = userLogin()
  64. """checks if username in searchlist is valid"""
  65. valid = searchList(username, password, username2, password2, Credentials)
  66. if valid == True:
  67. #Added spaces to make the UI look nicer
  68. print("")
  69. print("────────────────────────────────────────"
  70. "────────────────────────────────────────"
  71. "───────────████──███────────────────────"
  72. "──────────█████─████────────────────────"
  73. "────────███───███───████──███───────────"
  74. "────────███───███───██████████──────────"
  75. "────────███─────███───████──██──────────"
  76. "─────────████───████───███──██──────────"
  77. "──────────███─────██────██──██──────────"
  78. "──────██████████────██──██──██──────────"
  79. "─────████████████───██──██──██──────────"
  80. "────███────────███──██──██──██──────────"
  81. "────███─████───███──██──██──██──────────"
  82. "───████─█████───██──██──██──██──────────"
  83. "───██████───██──────██──────██──────────"
  84. "─████████───██──────██─────███──────────"
  85. "─██────██───██─────────────███──────────"
  86. "─██─────███─██─────────────███──────────"
  87. "─████───██████─────────────███──────────"
  88. "───██───█████──────────────███──────────"
  89. "────███──███───────────────███──────────"
  90. "────███────────────────────███──────────"
  91. "────███───────────────────███───────────"
  92. "─────████────────────────███────────────"
  93. "──────███────────────────███────────────"
  94. "────────███─────────────███─────────────"
  95. "────────████────────────██──────────────"
  96. "──────────███───────────██──────────────"
  97. "──────────████████████████──────────────"
  98. "──────────████████████████──────────────"
  99. "────────────────────────────────────────"
  100. "────────────────────────────────────────")
  101. print("")
  102. else:
  103. print("")
  104. print("User not valid or found")
  105. print("")
  106.  
  107. main()
  108. #Testing to see if usernames & passwords would read and print them in py shell
  109. #for x in Credentials:
  110. #print(x)
  111. main()
  112. #########################################################################################
  113. # Authenticator #
  114. #########################################################################################
  115.  
  116. #########################################################################################
  117.  
  118. #########################################################################################
  119. # Dice #
  120. #########################################################################################
  121.  
  122. def dice_even():
  123. """When an even number is rolled 10 will be added to the current value"""
  124. value = 10
  125. return(value)
  126.  
  127. def dice_odd():
  128. """When an odd number is rolled 5 will be taken away from the current value"""
  129. value = -5
  130. return(value)
  131.  
  132. def dice_roll():
  133. """count is set to 1 by deafult & score is set to 0 by default"""
  134. count = 1
  135. score = 0
  136. while count < 3:
  137. print("\n")
  138. print("Shaking dice\n")
  139. print("Rolling...")
  140. print("Rolling..")
  141. print("Rolling.")
  142. dice = random.randint(1,6)
  143. print("Dice", count, "thrown score is", dice, "\n")
  144. score = score + dice
  145. count = count + 1
  146. if score%2 == 0:
  147. print("an even number was thrown")
  148. score = dice_even()
  149. #print(score) | Testing score due to a logic error which has been fixed
  150. else:
  151. print("an even number was thrown")
  152. score = dice_odd()
  153. #print(score) | Testing score due to a logic error which has been fixed
  154. return(score)
  155.  
  156. def dice_main(username, username2):
  157. """All states of been assigned to false or 0 by deafault"""
  158. play = False
  159. p1Score = 0
  160. p2Score = 0
  161. p1RoundScore = 0
  162. p2RoundScore = 0
  163. dice_player1 = username # dice_player1 will call
  164. dice_player2 = username2
  165. gameRound = 0
  166. while gameRound < 5: # 0 - 5 | Zero is registered as number '1'
  167. p1RoundScore = dice_roll()
  168. p2RoundScore = dice_roll()
  169. p1Score = p1Score + p1RoundScore
  170. if p1Score <= 0:
  171. p1Score = 0
  172. p2Score = p2Score + p2RoundScore
  173. if p2Score <= 0:
  174. p2Score = 0
  175. gameRound = gameRound + 1
  176. input("Press enter to start next round")
  177. print(p1Score, p2Score)
  178. print("a")
  179. print("b")
  180. print("c")
  181. print("d")
  182. print("#" * 25)
  183.  
  184. #print("p1 score= ",p1Score)
  185. #print("p2 score= ",p2Score)
  186.  
  187. if p1Score > p2Score:
  188. print(dice_player1, "Win")
  189. elif p2Score > p1Score:
  190. print(dice_player2, "Win")
  191. else:
  192. print("draw")
  193. print(p1Score, p2Score)
  194.  
  195. dice_main()
  196.  
  197. #########################################################################################
  198. # Dice #
  199. #########################################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement