Guest User

game3

a guest
Jul 2nd, 2016
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.42 KB | None | 0 0
  1. import data
  2. words = data.words
  3. comments = data.comments
  4. intro1 = data.intro1
  5. instruc1 = data.instruc1
  6. instruc2 = data.instruc2
  7. import random
  8. import sys
  9. import os
  10. sboard = []
  11. bad_guesses = []
  12. good_guesses = []
  13. check = []
  14. score = 0
  15. secret_word = random.choice(words)
  16. wordindex = words.index("{}".format(secret_word))
  17.  
  18. def introduction():
  19.     clear()
  20.     print(intro1)
  21.     while True:
  22.         start = input("Press enter to start: ").lower()
  23.         if start == "quit":
  24.             clear()
  25.             sys.exit()
  26.         elif start == "instructions":
  27.             instructions()
  28.         elif start == "menu":
  29.             continue
  30.         elif start == "guess":
  31.             print("\nYou cannot guess yet!")
  32.             continue
  33.         elif start == "score":
  34.             scoreboard()
  35.         else:
  36.             setupgame()
  37.             main()
  38.  
  39. def setupgame():
  40.     clear()
  41.     global name
  42.     name = input("\n\n\nEnter your name (for the scoreboard): ")
  43.     if name.lower() == "menu":
  44.         introduction()
  45.     elif name.lower() == "quit":
  46.         clear()
  47.         sys.exit()
  48.     clear()
  49.     for letters in secret_word:
  50.         if letters not in check:
  51.             check.append(letters)
  52.         else:
  53.             continue
  54.     print('\n\n')
  55.     main()
  56.  
  57. def main():
  58.     print('\n\n')
  59.     while len(bad_guesses) <= 7:
  60.         print("\n\n\nClue:\n\n")
  61.         print(comments[wordindex])
  62.         print('\n\n\n')
  63.         for letter in secret_word:
  64.             if letter in good_guesses:
  65.                 print(letter, " ", end='')
  66.             else:
  67.                 print("_ ", end='')
  68.         print("\n\nYour score is: {}".format(score))
  69.         print("\nStrikes: {}/7\n".format(len(bad_guesses)))
  70.         print("Wrong guesses: \n")
  71.         for bguess in bad_guesses:
  72.             print(bguess, " ", end='')
  73.         print("\n\n\nOptions: 'guess' 'menu' 'quit'\n")
  74.         guess()
  75.     else:
  76.         clear()
  77.         print("\n\n\nYou didn't get it! LOSER!!! My word was '{}'.".format(secret_word))
  78.         print("\n\nYour score was: {}!\n".format(score))
  79.         result = name + " " + str(score)
  80.         sboard.append(result)
  81.         playagain()
  82.  
  83. def guess():
  84.     global userguess
  85.     userguess = input("Guess a letter: ").lower()
  86.     clear()
  87.     if userguess == "quit":
  88.         sys.exit()
  89.     elif userguess == "menu":
  90.         introduction()
  91.     elif userguess == "guess":
  92.         fullguess()
  93.     elif len(userguess) != 1:
  94.         print("\n\nYou must guess a (single) letter!")
  95.         main()
  96.     elif userguess in bad_guesses or userguess in good_guesses:
  97.         print("\n\nYou've already guessed that letter!")
  98.         main()
  99.     elif not userguess.isalpha():
  100.         print("\n\nYou can only guess letters!")
  101.         main()
  102.     good_bad()
  103.  
  104. def good_bad():
  105.     global score
  106.     if userguess in secret_word:
  107.         good_guesses.append(userguess)
  108.         score += 10
  109.         print("\n\nGood guess!")
  110.         if len(good_guesses) == len(check):
  111.             clear()
  112.             print("\n\n\nYOU WIN!!! The word was '{}'.\n".format(secret_word))
  113.             print("\n\nYour score was: {}!\n".format(score))
  114.             result = name + " " + str(score)
  115.             sboard.append(result)
  116.             playagain()
  117.         main()
  118.     else:
  119.         bad_guesses.append(userguess)
  120.         score -= 20
  121.         bad1 = int(len(bad_guesses))
  122.         if bad1 == 7:
  123.             print("\n\nNext incorrect answer means that you lose!!")
  124.         else:
  125.             print("\n\nUnlucky! You have used {} of your 7 wrong guesses!".format(bad1))
  126.         main()
  127.  
  128. def clear():
  129.     if os.name == 'nt':
  130.         os.system('cls')
  131.     else:
  132.         os.system('clear')
  133.  
  134. def playagain():
  135.     while True:
  136.         global bad_guesses, good_guesses, check, score, secret_word, wordindex
  137.         bad_guesses = []
  138.         good_guesses = []
  139.         check = []
  140.         score = 0
  141.         secret_word = random.choice(words)
  142.         wordindex = words.index("{}".format(secret_word))
  143.         play_again = input("""
  144. Options: 'yes' 'no' 'menu' 'score' 'quit'\n
  145. Would you like to play again?: """).lower()
  146.         if play_again == "yes":
  147.             setupgame()
  148.         elif play_again == "no" or play_again == "quit":
  149.             clear()
  150.             sys.exit()
  151.         elif play_again == "menu":
  152.             introduction()
  153.         elif play_again == "score":
  154.             scoreboard()
  155.         else:
  156.             clear()
  157.             print("\n\nYou must type either 'yes' or 'no'!\n\n")
  158.             continue
  159.  
  160. def instructions():
  161.     clear()
  162.     print(instruc1)
  163.     cont = input("Press enter to continue to page 2, 'Scoring And Scoreboard': ").lower()
  164.     if cont == "quit":
  165.         clear()
  166.         sys.exit()
  167.     elif cont == "menu":
  168.         introduction()
  169.     clear()
  170.     print(instruc2)
  171.     while True:
  172.         end = input("""Type 'menu' to return to the main menu, 'quit' to exit the game,
  173. or 'back' to go back to the previous page: """).lower()
  174.         if end == "menu":
  175.             introduction()
  176.         elif end == "quit":
  177.             clear()
  178.             sys.exit()
  179.         elif end == "back":
  180.             instructions()
  181.         else:
  182.             continue
  183.  
  184. def fullguess():
  185.     global score
  186.     clear()
  187.     print("\n\n\nThis is what you have so far:\n")
  188.     for letter in secret_word:
  189.         if letter in good_guesses:
  190.             print(letter, " ", end='')
  191.         else:
  192.             print("_ ", end='')
  193.     print("\nThe clue was:")
  194.     print(comments[wordindex])
  195.     print("\n\nEnter the word/phrase that you think is correct:")
  196.     print("(Type 'letters' to go back to guessing letter by letter)")
  197.     fguess = input("> ").lower()
  198.     if fguess == "quit":
  199.         clear()
  200.         sys.exit()
  201.     elif fguess == "menu":
  202.         introduction()
  203.     elif fguess == "letters":
  204.         clear()
  205.         print('\n\n')
  206.         main()
  207.     elif fguess == secret_word:
  208.         clear()
  209.         print("\n\n\nCONGRATULATIONS!!! You got it right!\n")
  210.         gscore = len(check) - len(good_guesses)
  211.         gscore *= 30
  212.         score += gscore
  213.         print("\nYour score was: {}!\n".format(score))
  214.         result = name + " " + str(score)
  215.         sboard.append(result)
  216.         playagain()
  217.     else:
  218.         clear()
  219.         print("\n\n\nOUCH!!! Bad luck, keep trying!")
  220.         score -= 50
  221.         print("\nYour score is: {}!\n".format(score))
  222.         while True:
  223.             g_again = input("Type 'again' to guess again, or 'letters' to go back to guessing by letter: ").lower()
  224.             if g_again == "again":
  225.                 fullguess()
  226.             elif g_again == "letters":
  227.                 clear()
  228.                 print('\n\n')
  229.                 main()
  230.             elif g_again == "quit":
  231.                 clear()
  232.                 sys.exit()
  233.             elif g_again == "menu":
  234.                 introduction()
  235.         main()
  236.  
  237. def scoreboard():
  238.     clear()
  239.     print("\n\n\nSCOREBOARD\n\n")
  240.     try:
  241.         print("1st PLACE:   ", sboard[0], "\n")
  242.     except IndexError:
  243.         print("1st PLACE:   \n")
  244.     num1 = 2
  245.     num2 = 1
  246.     while num1 <= 9:
  247.         try:
  248.             print("{}  > ".format(num1), sboard[num2])
  249.         except IndexError:
  250.             print("{}  > ".format(num1))
  251.         num1 += 1
  252.         num2 += 1
  253.     try:
  254.         print("10 > ", sboard[9])
  255.     except IndexError:
  256.         print("10 > ")
  257.     print("\n\n\n(Note: Type 'wipe' to refresh the scoreboard!)\n")
  258.     while True:
  259.         back = input("Type 'menu' to go back to the main menu, or 'quit' to exit the game: ").lower()
  260.         if back == "menu":
  261.             introduction()
  262.         elif back == "quit":
  263.             clear()
  264.             sys.exit()
  265.         elif back == "wipe":
  266.             global sboard
  267.             sboard = []
  268.             scoreboard()
  269.         else:
  270.             continue
  271.  
  272. introduction()
Advertisement
Add Comment
Please, Sign In to add comment