Advertisement
Guest User

Untitled

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