Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys,random,time,getpass,os
- #By Axnah1 on twitter
- if 'idlelib.run' in sys.modules: #a check to see if in idle or cmd, this is done because of my color code....
- os.system("py DiceGame.py")
- else:
- print("")#do nothing
- PlayerName = [None]*2
- PlayerScore = [0]*2
- PlayerDrawScore = [0]*2 #new array with 2 slots, both 0
- winner = -1
- if not os.path.isfile("Users.txt"): #if file doesn't exist
- file = open("Users.txt", "w")#creates the file
- def login():
- UserLogin = input("Enter Registered Username: ")
- if UserLogin != PlayerName[0]:
- PassLogin = input("Enter Password: ")
- f = open("Users.txt", "r+")
- lines = [line.rstrip()for line in f]
- for line in lines:
- Splitter = line.split(":")
- if Splitter[0] == UserLogin: # Username in Users.txt
- if Splitter[1] == PassLogin: #Pass in users
- f.close()
- print("Logged in...")
- print("Welcome to NEA Dice Game....")
- time.sleep(0.5)
- return UserLogin
- print("Username or password failed.")
- sys.exit()
- def Register():
- UserNameReg = input("Enter a username: ")
- f = open("Users.txt", "r+")
- lines = [line.rstrip()for line in f]
- for line in lines:
- Splitter = line.split(":")
- if Splitter[0] == UserNameReg or UserNameReg == "":
- f.close()
- print("Username Alredy Taken.")
- Register()
- return
- UserNamePass = input("Enter a password for "+UserNameReg+":")
- PassVerify = input("Please Re-Enter Password for verification: ")
- if PassVerify == UserNamePass:
- f.write(UserNameReg+":"+UserNamePass + "\n")
- f.close()
- print("Successfully Registered")
- return login()
- else:
- print("Failed")
- sys.exit()
- ######################################################################
- def CheckLogin():
- CheckIfAccount = input("Do you own a Account? y|n: ")
- if CheckIfAccount == 'y':
- Yeee = login() #Yeee is only a variable name, dont worry about it.
- if Yeee != None:
- return Yeee
- else:
- Yeex2 = Register()
- if Yeex2 != None:
- return Yeex2
- ######################################################################
- def Roll():
- return random.randint(1,6)
- def draw():
- while True:
- for Player in range(2):#2 players
- input(PlayerName[Player] + " press enter to roll")
- PlayerDrawScore[Player] = Roll()
- print(f"You rolled a {PlayerDrawScore[Player]}")
- if PlayerDrawScore[0] == PlayerDrawScore[1]:#draw again
- continue
- if PlayerDrawScore[0] > PlayerDrawScore[1]:#player1 wins
- PlayerScore[0] += PlayerDrawScore[0]
- return
- else:#player2 wins
- PlayerScore[1] += PlayerDrawScore[1]
- return
- ################################################################
- def PlayGame():
- for Round in range(5): #5 rounds
- for Player in range(2): #2 players
- PlayDie = input(f"Player {PlayerName[Player]} Press Enter to roll the dice: ") #f = format, player+1 so player1 and 2 not 0 1
- PRoll = Roll() #Primary Roll
- SRoll = Roll() #Secondary Roll
- Total = PRoll + SRoll #Primary Roll + Secondary Roll = Total
- parity = ""
- if Total % 2 == 0: #is even
- Total += 10#adds 10
- parity = "+10 for Even"
- else:
- Total -= 5#subtracts 5
- parity = "-5 for odd"
- if PRoll == SRoll: # checking for double roll
- TRoll = Roll() # Tertiary Roll
- print(f"You Rolled a Double and got a {TRoll}")
- Total += TRoll
- PlayerScore[Player] +=Total
- if PlayerScore[Player] < 0:
- PlayerScore[Player] = 0
- print(f"We are on round: {Round+1} {PlayerName[Player]} Rolled a {PRoll} and a {SRoll} {parity} for a total of {PlayerScore[Player]} " + "\n")
- print(f"The scores are {PlayerScore[0]} to {PlayerName[0]} and {PlayerScore[1]} to {PlayerName[1]}")
- if PlayerScore[0] == PlayerScore[1]:
- print("It's a draw for sudden death")
- draw()
- if PlayerScore[0] > PlayerScore[1]:
- winner = 0
- else:
- winner = 1
- f = open("Scores.txt", "a+")
- f.write(f"Winner {PlayerName[winner]} got a score of {PlayerScore[winner]}" + "\n")
- f.close()
- time.sleep(3)
- OpenNotify = input("Would you like to open scores? y|n: ")
- if OpenNotify == 'y':
- os.system("cls")
- os.system("start Scores.txt")
- else:
- os.system("cls")
- print("Okay, Proceeding to Rave...")
- time.sleep(1.5)
- print(f"Congratulations {PlayerName[winner]} For Winning With a score of {PlayerScore[winner]}| Press CTRL-C To Exit")
- for x in range(5000000):
- os.system("color a")
- os.system("color b")
- os.system("color c")
- os.system("color d")
- os.system("color e")
- os.system("color f")
- #print(f"{PlayerName[winner]} won")
- ################################################################
- PlayerName[0] = CheckLogin()
- PlayerName[1] = CheckLogin()
- PlayGame()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement