Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- class Login:
- def __init__(self):
- self.name = ""
- self.valid = False
- def menu(self):
- print("\n\n[!] Welcome, please login or make a new account.")
- while self.valid == False:
- choice = int(input("[?] Login (1) or Register (2) -> "))
- if(choice == 1):
- self.valid = True
- Login().login()
- elif(choice == 2):
- valid = True
- Login().register()
- else:
- self.valid = False
- print("\n[!] '"+str(choice)+"' isn't an option, please try again.")
- def login(self):
- userdb = open("userdb.txt", "r+")
- Username = input("[?] Username: ")
- Password = input("[?] Password: ")
- query = Username+":"+Password+"\n"
- for person in userdb:
- if query == person:
- print("\n[!] User found, welcome "+Username+"!")
- name = Username
- Game(name).menu()
- else:
- pass
- self.valid = False
- while self.valid == False:
- print("\n[!] Looks like we couldn't find a user in time.")
- choice = int(input("[?] Try again with different credentials (1) or return to main menu (2) -> "))
- if(choice == 1):
- self.valid = True
- Login().login()
- elif(choice == 2):
- valid = True
- Login().menu()
- else:
- self.valid = False
- print("\n[!] '"+str(choice)+"' isn't an option, please try again.")
- def register(self):
- userdb = open("userdb.txt", "r+")
- print("\n[!] Welcome, in order to create an account, please choose an username.")
- Username = input("[?] Username: ")
- print("[!] Now choose a secure password.")
- self.valid = False
- while self.valid == False:
- Password = input("[?] Password: ")
- if(Password == ""):
- Password = "guest"
- else:
- Password = Password
- if(len(Password)<5):
- print("\n[!] Your password seems to be very weak, please enter a stronger password.")
- self.valid = False
- else:
- self.valid = True
- query = "{}:{}".format(Username, Password)
- for person in userdb:
- if query == person:
- print("\n[!] A user with the same credentials is already registered, please try again.")
- Login().register()
- else:
- pass
- userdb.write(query + "\n")
- userdb.close()
- print("\n[!] You may login with your credentials.")
- Login().login()
- class Game:
- def __init__(self, name):
- self.name = name
- def menu(self):
- print("\n\n[!] Welcome to the game "+self.name+"! Would you like to start?")
- choice = int(input("[?] Start game (1) or return to login menu (2) -> "))
- if(choice == 1):
- self.valid = True
- Game(self.name).game()
- elif(choice == 2):
- valid = True
- Login().menu()
- else:
- self.valid = False
- print("\n[!] '"+str(choice)+"' isn't an option, please try again.")
- def game(self):
- print("\n[!] Let's begin!")
- songs = open("songs.txt", "r+") # Open song file
- randline = songs.read().splitlines()
- score = 0
- valid = True
- while valid:
- count = 0
- songs = []
- song = random.choice(randline).replace("_", " ").split(",")
- while count<4:
- songs.append(song[1][count])
- count+=1
- print("-"*20)
- print("\n[!] Song Name: "+songs[0]+songs[1]+songs[2]+songs[3])
- print("[!] Artist Name: " +song[0]+"\n")
- print("-"*20)
- a = " "+input("[?] Song? -> ").lower()
- answer = song[1].lower()
- if a == answer:
- print("\n[!] Well done "+self.name+", the song was:"+ song[1] + " by " + song[0])
- score+=1
- count = 0
- valid = True
- else:
- print("\n[!] Unlucky "+self.name+", the song was:" +song[1] + " by " + song[0])
- valid = False
- count = 0
- print("\n[!] Your score was: " + str(score))
- Login().menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement