Advertisement
Guest User

hmmm

a guest
Oct 30th, 2018
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.57 KB | None | 0 0
  1. import random
  2.  
  3. class Login:
  4.     def __init__(self):
  5.         self.name = ""
  6.         self.valid = False
  7.  
  8.     def menu(self):
  9.         print("\n\n[!] Welcome, please login or make a new account.")
  10.         while self.valid == False:
  11.             choice = int(input("[?] Login (1) or Register (2) -> "))
  12.             if(choice == 1):
  13.                 self.valid = True
  14.                 Login().login()
  15.             elif(choice == 2):
  16.                 valid = True
  17.                 Login().register()
  18.             else:
  19.                 self.valid = False
  20.                 print("\n[!] '"+str(choice)+"' isn't an option, please try again.")
  21.  
  22.     def login(self):
  23.         userdb = open("userdb.txt", "r+")
  24.         Username = input("[?] Username: ")
  25.         Password = input("[?] Password: ")
  26.         query = Username+":"+Password+"\n"
  27.         for person in userdb:
  28.             if query == person:
  29.                 print("\n[!] User found, welcome "+Username+"!")
  30.                 name = Username
  31.                 Game(name).menu()
  32.             else:
  33.                 pass
  34.         self.valid = False
  35.         while self.valid == False:
  36.             print("\n[!] Looks like we couldn't find a user in time.")
  37.             choice = int(input("[?] Try again with different credentials (1) or return to main menu (2) -> "))
  38.             if(choice == 1):
  39.                 self.valid = True
  40.                 Login().login()
  41.             elif(choice == 2):
  42.                 valid = True
  43.                 Login().menu()
  44.             else:
  45.                 self.valid = False
  46.                 print("\n[!] '"+str(choice)+"' isn't an option, please try again.")
  47.  
  48.     def register(self):
  49.         userdb = open("userdb.txt", "r+")
  50.         print("\n[!] Welcome, in order to create an account, please choose an username.")
  51.         Username = input("[?] Username: ")
  52.         print("[!] Now choose a secure password.")
  53.         self.valid = False
  54.         while self.valid == False:
  55.             Password = input("[?] Password: ")
  56.             if(Password == ""):
  57.                 Password = "guest"
  58.             else:
  59.                 Password = Password
  60.             if(len(Password)<5):
  61.                 print("\n[!] Your password seems to be very weak, please enter a stronger password.")
  62.                 self.valid = False
  63.             else:
  64.                 self.valid = True
  65.                 query = "{}:{}".format(Username, Password)
  66.                 for person in userdb:
  67.                     if query == person:
  68.                         print("\n[!] A user with the same credentials is already registered, please try again.")
  69.                         Login().register()
  70.                     else:
  71.                         pass
  72.                 userdb.write(query + "\n")
  73.                 userdb.close()
  74.                 print("\n[!] You may login with your credentials.")
  75.                 Login().login()
  76.  
  77.  
  78.  
  79. class Game:
  80.     def __init__(self, name):
  81.         self.name = name
  82.  
  83.     def menu(self):
  84.         print("\n\n[!] Welcome to the game "+self.name+"! Would you like to start?")
  85.         choice = int(input("[?] Start game (1) or return to login menu (2) -> "))
  86.         if(choice == 1):
  87.             self.valid = True
  88.             Game(self.name).game()
  89.         elif(choice == 2):
  90.             valid = True
  91.             Login().menu()
  92.         else:
  93.             self.valid = False
  94.             print("\n[!] '"+str(choice)+"' isn't an option, please try again.")
  95.  
  96.     def game(self):
  97.         print("\n[!] Let's begin!")
  98.         songs = open("songs.txt", "r+") # Open song file
  99.         randline = songs.read().splitlines()
  100.         score = 0
  101.         valid = True
  102.         while valid:
  103.             count = 0
  104.             songs = []
  105.             song = random.choice(randline).replace("_", " ").split(",")
  106.             while count<4:
  107.                 songs.append(song[1][count])
  108.                 count+=1
  109.             print("-"*20)
  110.             print("\n[!] Song Name: "+songs[0]+songs[1]+songs[2]+songs[3])
  111.             print("[!] Artist Name: " +song[0]+"\n")
  112.             print("-"*20)
  113.             a = " "+input("[?] Song? -> ").lower()
  114.             answer = song[1].lower()
  115.             if a == answer:
  116.                 print("\n[!] Well done "+self.name+", the song was:"+ song[1] + " by " + song[0])
  117.                 score+=1
  118.                 count = 0
  119.                 valid = True
  120.             else:
  121.                 print("\n[!] Unlucky "+self.name+", the song was:" +song[1] + " by " + song[0])
  122.                 valid = False
  123.                 count = 0
  124.                 print("\n[!] Your score was: " + str(score))
  125.  
  126.  
  127. Login().menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement