Guest User

Untitled

a guest
Jan 11th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.59 KB | None | 0 0
  1. import sys
  2. import random
  3. import time
  4. import re
  5. def unimportant():
  6.     print ("""====Welcome to the song name guessing game====
  7. ==============================================
  8. The aim of the game is to guess the correct
  9. name of the song with only the first letters
  10. of the name of the song and the full name of
  11. the artists.
  12. ==============================================""")
  13.     fro = open("Highscore.txt","r+")
  14.     rand = fro.write("0")
  15.     highscore = fro.read()
  16.     print ("Highscore is: ",highscore)
  17.     mainMenu()
  18. def mainMenu():
  19.     starter = input ("""Would you like to:
  20. 1. Log In
  21. 2. Sign Up
  22. 3. Exit
  23. 7. Force Start
  24. ==============================================\n>>""")
  25.     if starter == '1':
  26.         print('not implemented')
  27.         time.sleep(1.5)
  28.         mainMenu()
  29.     elif starter == '2':
  30.         print('not implemented')
  31.         time.sleep(1.5)
  32.         mainMenu()
  33.     elif starter == '3':
  34.         print('Exiting...')
  35.         time.sleep(1.5)
  36.         sys.exit()
  37.     elif starter == '7':
  38.         print('Loading game...')
  39.         time.sleep(1.5)
  40.         main()
  41.     else:
  42.         print("""=====================ERROR====================
  43. You have entered an invalid option, Please
  44. try again!
  45. ==============================================""")
  46.         mainMenu()
  47.        
  48. def main():
  49.     playerScore=0
  50.     guessCounter = 0
  51.     # This is where you can change the max turns and guesses
  52.     maxTurns=999999999
  53.     maxGuesses = 2
  54.     while True:
  55.         randNum = int(random.randint(0, 19))
  56.         f=open('Songs.txt')
  57.         linesa=f.read().splitlines()
  58.         g=open('Artists.txt')
  59.         linesb=g.read().splitlines()
  60.  
  61.         for turnCounter in range(maxTurns):
  62.             randNum = int(random.randint(0, 19))
  63.             f=open('Songs.txt')
  64.             linesa=f.read().splitlines()
  65.             g=open('Artists.txt')
  66.             linesb=g.read().splitlines()
  67.  
  68.             # Pick a random song:
  69.             print('==============================================')
  70.             randsong =(linesa[randNum])
  71.             randart =(linesb[randNum])
  72.             print(randsong)
  73.             print(randart)
  74.             print('==============================================')
  75.             # Prompt for a guess:
  76.             songGuess = input("What is the song called?\n==============================================\n>> ")
  77.  
  78.             # Let the user guess until they hit the max tries:
  79.             correctGuess = False
  80.             while not correctGuess:
  81.                 if songGuess.lower() == randsong.lower():
  82.                     guessCounter == 0
  83.                     playerScore += 1
  84.                     correctGuess = True
  85.                    
  86.                     break
  87.                    
  88.                 else:
  89.                     # Song wasn't guessed correctly and we haven't hit
  90.                     # the max guesses yet, so try again:
  91.                     guessCounter +=1
  92.                     if guessCounter<maxGuesses:
  93.                         songGuess = input("Incorrect! Try again:\n>> ")
  94.                     else:
  95.                         break
  96.  
  97.             # We're out of the while loop, so either the song was guessed
  98.             # correctly, or we hit the max number of guesses. Find out which:
  99.             if correctGuess == True:
  100.                 print("Answer correct!")
  101.                 correctGuess == False
  102.             else:
  103.                 print("""==================GAME  OVER==================
  104. Your score was:""", playerScore, """
  105. ==============================================""")
  106.                 fro = open("Highscore.txt","r+")
  107.                 x = fro.read()
  108.                 xx = 0
  109.                 xx == int(x)
  110.                 if xx < playerScore:
  111.                     fro.truncate(0)
  112.                     playerScor = str(playerScore)
  113.                     fro.write(playerScor)
  114.                 else:
  115.                     break
  116.                 guessCounter==0
  117.                 restartMenu()
  118.  
  119.         return
  120. def restartMenu():
  121.     restart = input("""==========Would you like to restart?==========
  122. 1. Yes
  123. 2. No
  124. ==============================================\n>>""")
  125.     if restart == '1':
  126.         main()
  127.     elif restart == 'yes':
  128.         main()
  129.     elif restart == 'Yes':
  130.         main()
  131.     elif restart == '2':
  132.         sys.exit(0)
  133.     elif restart == 'no':
  134.         sys.exit(0)
  135.     elif restart == 'No':
  136.         sys.exit(0)
  137.     else:
  138.         print("""=====================ERROR====================
  139. You have entered an invalid option, Please
  140. try again!
  141. ==============================================""")
  142.     restartMenu()
  143.    
  144. unimportant()
Add Comment
Please, Sign In to add comment