Advertisement
AlphaPenguino

HANGMAN 1.7

Sep 23rd, 2023 (edited)
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 11.39 KB | Source Code | 0 0
  1. import os
  2. width, height = 93, 28
  3. os.system(f'mode con: cols={width} lines={height}')
  4. os.system('mode con: cols=93 lines=28')
  5. def renderGraphics():
  6.     print(f"""_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
  7.                                                                                     -_
  8.                                                                                     -_
  9.                                                                                     -_
  10.                    ///>    {hidden1}   <///            
  11.  
  12.  
  13.                                                                                     -_
  14.                 Wrong Guesses: {wrongLetter}                
  15.                                                                                     -_
  16.  
  17.    """)
  18. def renderLoss():
  19.     print(f"""_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
  20.                                                                                     -_  
  21.                                                               /h - Show commands    -_
  22.                                                                                     -_
  23.                    ///>    {hidden1}   <///                
  24.  
  25.                                Gameover!, the word is '{wordX}'    
  26.                                                                                     -_
  27.                 Wrong Guesses: {wrongLetter}                
  28.                                                                                     -_
  29.  
  30.    """)
  31. def renderWon():
  32.     print(f"""_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
  33.                                                                                     -_  
  34.                                                               /h - Show commands    -_
  35.                                                                                     -_
  36.                    ///>    {hidden1}   <///            
  37.                    You got the right answer!  
  38.                                The answer is '{wordX}'
  39.                                                                                     -_
  40.                 Wrong Guesses: {wrongLetter}                
  41.                                                                                     -_
  42.  
  43.    """)
  44. def hangman(tries):
  45.     if tries == 0:
  46.         print("""
  47.                                                                                    +
  48.         _   _                                           __        ______           |
  49.        | | | |                                         /  |      |___  /           |
  50.        | |_| | __ _ _ __   __ _ _ __ ___   __ _ _ __   `| |         / /            |
  51.        |  _  |/ _` | '_ \ / _` | '_ ` _ \ / _` | '_ \  | |        / /             |
  52.        | | | | (_| | | | | (_| | | | | | | (_| | | | | _| |_  _  ./ /              |
  53.        \_| |_/\__,_|_| |_|\__, |_| |_| |_|\__,_|_| |_| \___/ (_) \_/         =========
  54.                            __/ |                                        
  55.                           |___/""")
  56.     if tries == 1:
  57.         print("""
  58.                                                                                +---+
  59.         _   _                                           __        ______       |   |
  60.        | | | |                                         /  |      |___  /           |
  61.        | |_| | __ _ _ __   __ _ _ __ ___   __ _ _ __   `| |         / /            |
  62.        |  _  |/ _` | '_ \ / _` | '_ ` _ \ / _` | '_ \  | |        / /             |
  63.        | | | | (_| | | | | (_| | | | | | | (_| | | | | _| |_  _  ./ /              |
  64.        \_| |_/\__,_|_| |_|\__, |_| |_| |_|\__,_|_| |_| \___/ (_) \_/         =========
  65.                            __/ |                                        
  66.                           |___/""")
  67.     if tries == 2:
  68.         print("""
  69.                                                                                +---+
  70.         _   _                                           __        ______       |   |
  71.        | | | |                                         /  |      |___  /       O   |
  72.        | |_| | __ _ _ __   __ _ _ __ ___   __ _ _ __   `| |         / /            |
  73.        |  _  |/ _` | '_ \ / _` | '_ ` _ \ / _` | '_ \  | |        / /             |
  74.        | | | | (_| | | | | (_| | | | | | | (_| | | | | _| |_  _  ./ /              |
  75.        \_| |_/\__,_|_| |_|\__, |_| |_| |_|\__,_|_| |_| \___/ (_) \_/         =========
  76.                            __/ |
  77.                           |___/""")
  78.     if tries == 3:
  79.         print("""
  80.                                                                                +---+
  81.         _   _                                           __        ______       |   |
  82.        | | | |                                         /  |      |___  /       O   |
  83.        | |_| | __ _ _ __   __ _ _ __ ___   __ _ _ __   `| |         / /        |   |
  84.        |  _  |/ _` | '_ \ / _` | '_ ` _ \ / _` | '_ \  | |        / /             |
  85.        | | | | (_| | | | | (_| | | | | | | (_| | | | | _| |_  _  ./ /              |
  86.        \_| |_/\__,_|_| |_|\__, |_| |_| |_|\__,_|_| |_| \___/ (_) \_/         =========
  87.                            __/ |                                        
  88.                           |___/""")
  89.     if tries == 4:
  90.         print("""
  91.                                                                                +---+
  92.         _   _                                           __        ______       |   |
  93.        | | | |                                         /  |      |___  /       O   |
  94.        | |_| | __ _ _ __   __ _ _ __ ___   __ _ _ __   `| |         / /       /|   |
  95.        |  _  |/ _` | '_ \ / _` | '_ ` _ \ / _` | '_ \  | |        / /             |
  96.        | | | | (_| | | | | (_| | | | | | | (_| | | | | _| |_  _  ./ /              |
  97.        \_| |_/\__,_|_| |_|\__, |_| |_| |_|\__,_|_| |_| \___/ (_) \_/         =========      
  98.                            __/ |                                        
  99.                           |___/""")
  100.     if tries == 5:
  101.         print("""
  102.                                                                                +---+
  103.         _   _                                           __        ______       |   |
  104.        | | | |                                         /  |      |___  /       O   |
  105.        | |_| | __ _ _ __   __ _ _ __ ___   __ _ _ __   `| |         / /       /|\ |
  106.        |  _  |/ _` | '_ \ / _` | '_ ` _ \ / _` | '_ \  | |        / /             |
  107.        | | | | (_| | | | | (_| | | | | | | (_| | | | | _| |_  _  ./ /              |
  108.        \_| |_/\__,_|_| |_|\__, |_| |_| |_|\__,_|_| |_| \___/ (_) \_/         =========      
  109.                            __/ |                                        
  110.                           |___/""")
  111.     if tries == 6:
  112.         print("""
  113.                                                                                +---+
  114.         _   _                                           __        ______       |   |
  115.        | | | |                                         /  |      |___  /       O   |
  116.        | |_| | __ _ _ __   __ _ _ __ ___   __ _ _ __   `| |         / /       /|\ |
  117.        |  _  |/ _` | '_ \ / _` | '_ ` _ \ / _` | '_ \  | |        / /        /    |
  118.        | | | | (_| | | | | (_| | | | | | | (_| | | | | _| |_  _  ./ /              |
  119.        \_| |_/\__,_|_| |_|\__, |_| |_| |_|\__,_|_| |_| \___/ (_) \_/         =========  
  120.                            __/ |                                        
  121.                           |___/""")
  122.     if tries == 7:
  123.         print("""
  124.                                                                                +---+
  125.         _   _                                           __        ______       |   |
  126.        | | | |                                         /  |      |___  /       O   |
  127.        | |_| | __ _ _ __   __ _ _ __ ___   __ _ _ __   `| |         / /       /|\ |
  128.        |  _  |/ _` | '_ \ / _` | '_ ` _ \ / _` | '_ \  | |        / /        / \ |
  129.        | | | | (_| | | | | (_| | | | | | | (_| | | | | _| |_  _  ./ /              |
  130.        \_| |_/\__,_|_| |_|\__, |_| |_| |_|\__,_|_| |_| \___/ (_) \_/         =========  
  131.                     __/ |                                        
  132.                |___/    Programmer: Zunder Jacob A. Pacis""")
  133. def space(x):
  134.     for i in range(x):
  135.         print()
  136.        
  137. gameStart = True
  138. while gameStart: #live-game
  139.     hangman(7)
  140.     word = str(input("Enter a word: "))
  141.     wordX = word.upper()
  142.     clue = str(input("Enter a clue: "))
  143.     space(50)
  144.     hidden = [char for char in wordX]
  145.     word1 = [char for char in wordX]  # word converted to chars
  146.     for i, char in enumerate(hidden):
  147.         if hidden[i] == " ":
  148.             hidden[i] = " "
  149.         else:
  150.             hidden[i] = "_ "
  151.     gameStart = True
  152.     mistakes = 0
  153.     wrongLetter = []
  154.     while (True):
  155.         # hidden = [char for char in word]
  156.         hidden1 = ''.join(hidden)
  157.         space(50)
  158.         hangman(mistakes)
  159.         print(f"\t\tClue: {clue}")
  160.         renderGraphics()
  161.         if hidden1 == wordX:
  162.             space(50)
  163.             hangman(mistakes)
  164.             renderWon()
  165.             break
  166.         user_input = str(input("Player input > "))
  167.         guessX = user_input.upper()
  168.         if user_input == "/q":
  169.             gameStart = False
  170.             break
  171.         if user_input == "/e":
  172.             break
  173.         if user_input == "print compare":
  174.             print(f"hidden1 = {hidden1}\nwordX = {wordX}")
  175.         if guessX == wordX:
  176.             space(50)
  177.             hidden1 = guessX
  178.             hangman(mistakes)
  179.             renderWon()
  180.             break
  181.         if guessX in wordX:
  182.             for i, char in enumerate(word1):
  183.                 if char == guessX:
  184.                     # print(f"{guess} = index b{i}")
  185.                     hidden[i] = guessX
  186.             print("correct!")
  187.         else:
  188.             # print(f"mali bobo, tries left: {tries}")
  189.             wrongLetter.append(guessX)
  190.             mistakes += 1
  191.         if mistakes == 7:
  192.             space(50)
  193.             hangman(mistakes)
  194.             renderLoss()
  195.             # print(f"gameover!, the word is '{word.upper()}'")
  196.             break
  197.     while (True):
  198.         if gameStart != False:
  199.             user_input = str(input("Console input > "))
  200.             if user_input == "/q":
  201.                 gameStart = False
  202.                 break
  203.             elif user_input == "/root":
  204.                 break
  205.             elif user_input == "/p":
  206.                 space(100)
  207.                 break
  208.             elif user_input == "/?":
  209.                 print("""
  210. Hangman is a word-guessing game where one player thinks of a word or phrase
  211. and writes down blank spaces for each letter. Other players take turns guessing
  212. letters, trying to fill in the blanks. If they guess a letter correctly,
  213. it's filled in; if not, part of a hangman figure is drawn. The game continues
  214. until the word is guessed or the hangman is fully drawn. Players win by guessing
  215. the word or lose if the hangman is completed. It's a fun and challenging game to
  216. test vocabulary and deduction skills.
  217.                                """)
  218.             elif user_input == "/h":
  219.                 print("/h - Show commands\n/q - Quit\n/e - Switch to Console (During game)\n/p - Play Again\n/? - Rules")
  220.         else:
  221.             break
  222.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement