Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os.path, time, random
- from datetime import datetime
- from time import sleep
- now = datetime.now()
- zero = ":"
- if len(str(now.minute)) == 1:
- zero = (":"+str(0))
- def welcome():
- 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),".")
- option = str(input("Please choose what you would like to do:\n1. Register\n2. Login\n3. Quit\n"))
- if option == "1":
- register()
- elif option == "2":
- login()
- else:
- quit
- def register():
- username = str(input("Create a username:\n"))
- if not os.path.isfile(username+".txt"):
- password = str(input("Input a password:\n"))
- confirm_password = str(input("Confirm your password:\n"))
- if password == confirm_password:
- user_file = open(username+".txt", "w")
- user_file.write(password)
- user_file.close()
- print("Successfully registered")
- welcome()
- else:
- print("Failed to confirm password, please try again")
- register()
- else:
- print(username,"already exists, please try again.")
- register()
- def login():
- username = str(input("Input your username:\n"))
- if os.path.isfile(username+".txt"):
- input_password = str(input("Input your password:\n"))
- user_file = open(username+".txt", "r")
- read_file = user_file.readlines()
- password = read_file[0]
- if password == input_password:
- print("Logged in as",username)
- else:
- print("Wrong password, try again")
- login()
- else:
- print("There is no Username called:",username)
- welcome()
- person1_name = input("Player 1, what is your name: ")
- person2_name = input("Player 2, what is your name: ")
- names = [person1_name, person2_name]
- totals = [0, 0]
- rolls = 1
- maxrolls = 2
- def roll():
- random.seed(datetime.now())
- player = 0
- while player <= 1:
- number1, number2 = random.randint(1,2), random.randint(1,2)
- print(names[player], "- 1st roll =", number1, "and 2nd roll =", number2)
- total = number1 + number2
- if total % 2 == 0:
- total += 10
- else:
- if total < 4:
- total = 0
- else:
- total -= 5
- print(names[player]," has rolled", total, "points.")
- totals[player] += total
- player += 1
- def checkscores():
- print("\nFinal results: ", names[0], totals[0],"-",totals[1] , person2_name)
- if totals[0] > totals[1]:
- print(person1_name," is the winner! ")
- elif totals[0] == totals[1]:
- print("\nIt's overtime!")
- roll()
- checkscores()
- else:
- print(person2_name," is the winner! ")
- while rolls <= maxrolls:
- print("\nRoll", rolls)
- rolls += 1
- roll()
- checkscores()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement