Advertisement
Guest User

Updated NEA

a guest
Jun 26th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.35 KB | None | 0 0
  1. import sys,random,time,getpass,os
  2. #By Axnah1 on twitter
  3. if 'idlelib.run' in sys.modules: #a check to see if in idle or cmd, this is done because of my color code....
  4.        os.system("py DiceGame.py")
  5. else:
  6.         print("")#do nothing
  7. PlayerName = [None]*2
  8. PlayerScore = [0]*2
  9. PlayerDrawScore = [0]*2 #new array with 2 slots, both 0
  10. winner = -1
  11. if not os.path.isfile("Users.txt"): #if file doesn't exist
  12.     file = open("Users.txt", "w")#creates the file
  13.  
  14.  
  15. def login():
  16.    
  17.     UserLogin = input("Enter Registered Username: ")
  18.     if UserLogin != PlayerName[0]:
  19.  
  20.         PassLogin = input("Enter Password: ")
  21.         f = open("Users.txt", "r+")
  22.         lines = [line.rstrip()for line in f]
  23.         for line in lines:
  24.             Splitter = line.split(":")
  25.             if Splitter[0] == UserLogin: # Username in Users.txt
  26.                 if Splitter[1] == PassLogin: #Pass in users
  27.                     f.close()
  28.                     print("Logged in...")
  29.                     print("Welcome to NEA Dice Game....")
  30.                     time.sleep(0.5)
  31.                     return UserLogin
  32.  
  33.     print("Username or password failed.")
  34.     sys.exit()
  35.  
  36. def Register():
  37.     UserNameReg = input("Enter a username: ")
  38.     f = open("Users.txt", "r+")
  39.     lines = [line.rstrip()for line in f]
  40.     for line in lines:
  41.         Splitter = line.split(":")
  42.         if Splitter[0] == UserNameReg or UserNameReg == "":
  43.             f.close()
  44.             print("Username Alredy Taken.")
  45.             Register()
  46.             return
  47.  
  48.     UserNamePass = input("Enter a password for "+UserNameReg+":")
  49.     PassVerify = input("Please Re-Enter Password for verification: ")
  50.     if PassVerify == UserNamePass:
  51.         f.write(UserNameReg+":"+UserNamePass + "\n")
  52.         f.close()
  53.         print("Successfully Registered")
  54.         return login()
  55.     else:
  56.         print("Failed")
  57.         sys.exit()
  58. ######################################################################
  59. def CheckLogin():
  60.     CheckIfAccount = input("Do you own a Account? y|n: ")
  61.     if CheckIfAccount == 'y':
  62.         Yeee = login() #Yeee is only a variable name, dont worry about it.
  63.         if Yeee != None:
  64.             return Yeee
  65.     else:
  66.         Yeex2 = Register()
  67.         if Yeex2 != None:
  68.             return Yeex2
  69. ######################################################################
  70. def Roll():
  71.     return random.randint(1,6)
  72.  
  73. def draw():
  74.     while True:
  75.         for Player in range(2):#2 players
  76.             input(PlayerName[Player] + " press enter to roll")
  77.             PlayerDrawScore[Player] = Roll()
  78.             print(f"You rolled a {PlayerDrawScore[Player]}")
  79.         if PlayerDrawScore[0] == PlayerDrawScore[1]:#draw again
  80.             continue
  81.         if PlayerDrawScore[0] > PlayerDrawScore[1]:#player1 wins
  82.             PlayerScore[0] += PlayerDrawScore[0]
  83.             return
  84.         else:#player2 wins
  85.             PlayerScore[1] += PlayerDrawScore[1]
  86.             return
  87. ################################################################
  88. def PlayGame():
  89.     for Round in range(5): #5 rounds
  90.         for Player in range(2): #2 players
  91.             PlayDie = input(f"Player {PlayerName[Player]} Press Enter to roll the dice: ") #f = format, player+1 so player1 and 2 not 0 1
  92.             PRoll = Roll() #Primary Roll
  93.             SRoll = Roll() #Secondary Roll
  94.             Total = PRoll + SRoll #Primary Roll + Secondary Roll = Total
  95.             parity = ""
  96.            
  97.             if Total % 2 == 0: #is even
  98.                 Total += 10#adds 10
  99.                 parity = "+10 for Even"
  100.             else:
  101.                 Total -= 5#subtracts 5
  102.                 parity = "-5 for odd"
  103.            
  104.             if PRoll == SRoll: # checking for double roll
  105.                 TRoll = Roll() # Tertiary Roll
  106.                 print(f"You Rolled a Double and got a {TRoll}")
  107.                 Total += TRoll
  108.  
  109.             PlayerScore[Player] +=Total
  110.             if PlayerScore[Player] < 0:
  111.                 PlayerScore[Player] = 0
  112.             print(f"We are on round: {Round+1} {PlayerName[Player]} Rolled a {PRoll} and a {SRoll} {parity} for a total of {PlayerScore[Player]} " + "\n")
  113.     print(f"The scores are {PlayerScore[0]} to {PlayerName[0]} and {PlayerScore[1]} to {PlayerName[1]}")
  114.     if PlayerScore[0] == PlayerScore[1]:
  115.         print("It's a draw for sudden death")
  116.         draw()
  117.     if PlayerScore[0] > PlayerScore[1]:
  118.         winner = 0
  119.     else:
  120.         winner = 1
  121.     f = open("Scores.txt", "a+")
  122.     f.write(f"Winner {PlayerName[winner]} got a score of {PlayerScore[winner]}" + "\n")
  123.     f.close()
  124.     time.sleep(3)
  125.     OpenNotify = input("Would you like to open scores? y|n: ")
  126.     if OpenNotify == 'y':
  127.         os.system("cls")
  128.         os.system("start Scores.txt")
  129.     else:
  130.         os.system("cls")
  131.         print("Okay, Proceeding to Rave...")
  132.         time.sleep(1.5)
  133.     print(f"Congratulations {PlayerName[winner]} For Winning With a score of {PlayerScore[winner]}| Press CTRL-C To Exit")
  134.     for x in range(5000000):
  135.        
  136.         os.system("color a")
  137.         os.system("color b")
  138.         os.system("color c")
  139.         os.system("color d")
  140.         os.system("color e")
  141.         os.system("color f")
  142.     #print(f"{PlayerName[winner]} won")
  143.  
  144. ################################################################
  145. PlayerName[0] = CheckLogin()
  146. PlayerName[1] = CheckLogin()
  147. PlayGame()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement