Advertisement
Guest User

Untitled

a guest
Nov 29th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. import os.path, time, random
  2. from datetime import datetime
  3. from time import sleep
  4. now = datetime.now()
  5. zero = ":"
  6. if len(str(now.minute)) == 1:
  7. zero = (":"+str(0))
  8.  
  9. def verify():
  10. unverified = True
  11. while unverified:
  12. pwd = input("Please enter the program's authorization code: ")
  13. if pwd == "1234":
  14. unverified = False
  15. welcome()
  16. else:
  17. print("Incorrect code entered.")
  18.  
  19. def welcome():
  20. print("Hi! Welcome to the dice game, the current time is %s%s%s and the date is %s/%s/%s\n" % (now.hour, zero, now.minute, now.day, now.month, now.year),".")
  21. option = str(input("Please choose what option you would like to select:\n1. Register\n2. Login\n3. Quit\n"))
  22. if option == "1": register()
  23. elif option == "2": login()
  24. else: quit
  25.  
  26. def register():
  27. username = str(input("Please create a username:\n"))
  28. if not os.path.isfile(username+".txt"):
  29. password = str(input("Please input a password:\n"))
  30. confirm_password = str(input("Please confirm your password:\n"))
  31. if password == confirm_password:
  32. user_file = open(username+".txt", "w")
  33. user_file.write(password)
  34. user_file.close()
  35. print("You have now successfully registered and you are ready to play!")
  36. welcome()
  37. else:
  38. print("Failed to confirm password, please try again")
  39. register()
  40. else:
  41. print(username,"already exists, please try using a different one.")
  42. register()
  43.  
  44. def login():
  45. username = str(input("Please input your username:\n"))
  46. if os.path.isfile(username+".txt"):
  47. input_password = str(input("Please input your password:\n"))
  48. user_file = open(username+".txt", "r")
  49. read_file = user_file.readlines()
  50. password = read_file[0]
  51. if password == input_password:
  52. print("You have now logged in as",username)
  53. game()
  54. else:
  55. print("Sorry but that is the wrong password, please try again")
  56. login()
  57. else:
  58. print("There is no Username called:",username)
  59.  
  60. def roll(names, totals):
  61.  
  62. random.seed(datetime.now())
  63. player = 0
  64. while player <= 1:
  65. number1, number2 = random.randint(1,6), random.randint(1,6)
  66. print(names[player], "- 1st roll =", number1, "and 2nd roll =", number2)
  67.  
  68. total = number1 + number2
  69.  
  70. if total % 2 == 0:
  71. total += 10
  72.  
  73. else:
  74. if total < 4:
  75. total = 0
  76. else:
  77. total -= 5
  78.  
  79. print(names[player]," has rolled", total, "points.")
  80.  
  81. totals[player] += total
  82. player += 1
  83. sleep(2)
  84.  
  85. def checkscores(names, totals):
  86. print("\nFinal results: ", names[0], totals[0],"-",totals[1] , names[1])
  87. if totals[0] > totals[1]:
  88. print(names[0]," is the winner! ")
  89. elif totals[0] == totals[1]:
  90. print("\nIt's now sudden death!")
  91. roll(names, totals)
  92. checkscores(names, totals)
  93. else:
  94. print(names[1]," is the winner! ")
  95.  
  96. #Main Game code
  97. def game():
  98. person1_name = input("Player 1, what is your name: ")
  99. person2_name = input("Player 2, what is your name: ")
  100.  
  101. names = [person1_name, person2_name]
  102. totals = [0, 0]
  103. rolls = 1
  104. maxrolls = 5
  105.  
  106. while rolls <= maxrolls:
  107. print("\nRoll", rolls)
  108. rolls += 1
  109. roll(names, totals)
  110. checkscores(names, totals)
  111.  
  112. verify()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement