Advertisement
Guest User

Untitled

a guest
Nov 28th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.98 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 welcome():
  10.     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),".")
  11.     option = str(input("Please choose what option you would like to select:\n1. Register\n2. Login\n3. Quit\n"))
  12.     if   option == "1":  register()
  13.     elif option == "2":  login()
  14.     else:                quit
  15.  
  16. def register():
  17.     username = str(input("Please create a username:\n"))
  18.     if not os.path.isfile(username+".txt"):
  19.         password = str(input("Please input a password:\n"))
  20.         confirm_password = str(input("Please confirm your password:\n"))
  21.         if password == confirm_password:
  22.             user_file = open(username+".txt", "w")
  23.             user_file.write(password)
  24.             user_file.close()
  25.             print("You have now successfully registered and you are ready to play!")
  26.             welcome()
  27.         else:
  28.             print("Failed to confirm password, please try again")
  29.             register()
  30.     else:
  31.         print(username,"already exists, please try using a different one.")
  32.         register()
  33.  
  34. def login():
  35.     username = str(input("Please input your username:\n"))
  36.     if os.path.isfile(username+".txt"):
  37.         input_password = str(input("Please input your password:\n"))
  38.         user_file = open(username+".txt", "r")
  39.         read_file = user_file.readlines()
  40.         password = read_file[0]
  41.         if password == input_password:
  42.             print("You have now logged in as",username)
  43.         else:
  44.             print("Sorry but that is the wrong password, please try again")
  45.             login()
  46.     else:
  47.         print("There is no Username called:",username)
  48.  
  49. def roll():
  50.     player = 0
  51.     while player <= 1:
  52.         number1, number2 = random.randint(1,6), random.randint(1,6)
  53.         print(names[player], "- 1st roll =", number1, "and 2nd roll =", number2)
  54.         total = number1 + number2
  55.         if total % 2 == 0: total += 10
  56.         else:
  57.             if total < 4: total = 0
  58.             else: total -= 5
  59.         print(names[player]," has rolled", total, "points.")
  60.         totals[player] += total
  61.         player += 1
  62.     sleep(1)
  63.  
  64. def checkscores():
  65.     print("\nFinal results: ", names[0], totals[0],"-",totals[1] , person2_name)
  66.     if totals[0] > totals[1]:
  67.         print(person1_name," is the winner! ")
  68.     elif totals[0] == totals[1]:
  69.         print("\nIt's now sudden death!")
  70.         roll()
  71.         checkscores()
  72.     else:
  73.         print(person2_name," is the winner! ")
  74.  
  75. welcome()
  76. person1_name, person2_name = input("Player 1, what is your name: "), input("Player 2, what is your name: ")
  77. names  = [person1_name, person2_name]
  78. totals, rolls, maxrolls = [0, 0], 1, 5
  79. while rolls <= maxrolls:
  80.     print("\nRoll", rolls)
  81.     rolls += 1
  82.     roll()
  83. checkscores()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement