Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #this imports the different libraries I will be using
- import random
- import math
- import sys
- import time
- import webbrowser
- def loadsongs():
- #this creates an empty list, which then has a text file loaded into it
- songlist = []
- #opens the file
- file = open("songs.txt","r")
- for line in file:
- songlist.append(line)
- file.close()
- #this loads the next function
- print(songlist)
- randomsong(songlist)
- def randomsong(songlist):
- #this sets the starting score and number of guesses to 0
- score = 0
- guesses = 0
- while len(songlist) and guesses < 2:
- #this selects a random song from the list and puts it into two different variables
- choice = random.choice(songlist)
- split = choice.find("by")
- song = choice[:split]
- artist = choice[split:]
- songcaps = song.upper()
- songcapsletter = songcaps[0]
- #this selects a song from the list at random
- print("")
- print(songcapsletter)
- print(artist)
- guess = str(input("What is the name of this song?: "))
- guesscaps = guess.upper()
- if guesscaps == songcaps:
- #this adds 3 to the score if the user gets the answer right
- score = score + 3
- print("Wow! You exist!")
- print("")
- print("Your current score is",score)
- #this takes the correctly guessed song out of the list
- songlist.remove(choice)
- guesses = 0
- else:
- guesses = guesses + 1
- guess = str(input("Sorry, but our princess is in another castle! guess again: "))
- guesscaps = guess.upper()
- if songcaps == guesscaps:
- print("Second times a charm or whatever")
- print("")
- score = score + 1
- print("Your current score is",score)
- songlist.remove(choice)
- guesses = 0
- else:
- print ("game over, your final score was",score)
- #this ends the game and adds the score to the leaderboard
- guesses = guesses + 1
- score = str(score)
- file = open("scores.txt","a+")
- file.write(username)
- file.write(",")
- file.write(score)
- file.write("\n")
- file.close()
- leaderboard()
- def leaderboard():
- scoreslist = []
- file = open("scores.txt")
- for line in file:
- splits = line.split(",")
- points = splits[1]
- name = splits[0]
- points = int(points)
- scoreslist.append([points,name])
- for i in range(5):
- maximumscore = max(scoreslist)
- place = i + 1
- maxname = maximumscore[1]
- maxscore = maximumscore[0]
- scoreslist.remove(maximumscore)
- print("In position number",place,"is",maxname,"with a score of",maxscore)
- time.sleep(1)
- file.close()
- time.sleep(5)
- mainmenu()
- def instructions():
- #this prints the instructions when the menu option is selected
- print("""in this game, a random song name and artist are chosen.
- the artist and first letter of each word in the song title are then displayed.
- you have 2 chances to guess the song.
- answering correctly on your first try gives you 3 points.
- if its guesses correctly the second time, you get 1 point.
- the game ends when you get the song incorrect the second time.
- enter 'close' to exit""")
- #this prints an ASCII image of a cake if "cake" is entered on the instruction menu
- eastereggcommand = str(input())
- if eastereggcommand == "cake":
- asciicake = open("cake.txt", "r")
- print(asciicake.read())
- asciicake.close
- time.sleep(3)
- mainmenu()
- if eastereggcommand == ("close"):
- mainmenu()
- def mainmenu():
- print("""< : : : : : WELCOME TO THE MUSIC GAME : : : : : >
- Please input your menu choice:
- 1. PLAY GAME
- 2. LEADERBOARD
- 3. INSTRUCTIONS
- 4. EXIT
- 5. BUY BATTLE PASS""")
- #user input for choice
- switch = False
- while switch ==False:
- while True:
- try:
- choice = int(input())
- if choice == 1:
- loadsongs()
- if choice == 2:
- leaderboard()
- if choice == 3:
- instructions()
- if choice == 4:
- exit()
- if choice == 5:
- webbrowser.open_new("https://www.paladins.com/battle-pass")
- break
- except ValueError:
- print ("not a number")
- def choose():
- #this asks the user if they want to signup or login
- print("Welcome! Would you like to login (1) or signup (2)?: ")
- choice = int(input())
- if choice == 1:
- #redirection to the login function
- login()
- if choice == 2:
- #redirection to the signup function
- signup()
- def signup():
- #this code asks the user to enter new information, which is then put into a text file and read from whenever the user logs in
- newUsername = str(input("Please enter a new username: "))
- newPassword = str(input("Please enter a new password: "))
- info = open("info.txt","a+")
- info.write(newUsername)
- info.write(newPassword)
- info.write("\n")
- print("Thank you for creating a new account")
- print("You will now be redirected to the login screen")
- info.close()
- login()
- def login():
- #this asks the user to input the username and password
- file = open("info.txt","r")
- global username
- username = str(input("Please input your username: "))
- password = str(input("Please input your password: "))
- combined = username+password
- #this allows the user access if their name and password are in the file, and repeats the login() function if they input incorrect info
- for line in file:
- if combined in line:
- print ("access granted")
- file.close()
- mainmenu()
- if combined not in file:
- print("access denied")
- file.close()
- login()
- choose()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement