Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- width, height = 93, 28
- os.system(f'mode con: cols={width} lines={height}')
- os.system('mode con: cols=93 lines=28')
- def renderGraphics():
- print(f"""_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
- -_
- -_
- -_
- ///> {hidden1} <///
- -_
- Wrong Guesses: {wrongLetter}
- -_
- """)
- def renderLoss():
- print(f"""_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
- -_
- /h - Show commands -_
- -_
- ///> {hidden1} <///
- Gameover!, the word is '{wordX}'
- -_
- Wrong Guesses: {wrongLetter}
- -_
- """)
- def renderWon():
- print(f"""_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
- -_
- /h - Show commands -_
- -_
- ///> {hidden1} <///
- You got the right answer!
- The answer is '{wordX}'
- -_
- Wrong Guesses: {wrongLetter}
- -_
- """)
- def hangman(tries):
- if tries == 0:
- print("""
- +
- _ _ __ ______ |
- | | | | / | |___ / |
- | |_| | __ _ _ __ __ _ _ __ ___ __ _ _ __ `| | / / |
- | _ |/ _` | '_ \ / _` | '_ ` _ \ / _` | '_ \ | | / / |
- | | | | (_| | | | | (_| | | | | | | (_| | | | | _| |_ _ ./ / |
- \_| |_/\__,_|_| |_|\__, |_| |_| |_|\__,_|_| |_| \___/ (_) \_/ =========
- __/ |
- |___/""")
- if tries == 1:
- print("""
- +---+
- _ _ __ ______ | |
- | | | | / | |___ / |
- | |_| | __ _ _ __ __ _ _ __ ___ __ _ _ __ `| | / / |
- | _ |/ _` | '_ \ / _` | '_ ` _ \ / _` | '_ \ | | / / |
- | | | | (_| | | | | (_| | | | | | | (_| | | | | _| |_ _ ./ / |
- \_| |_/\__,_|_| |_|\__, |_| |_| |_|\__,_|_| |_| \___/ (_) \_/ =========
- __/ |
- |___/""")
- if tries == 2:
- print("""
- +---+
- _ _ __ ______ | |
- | | | | / | |___ / O |
- | |_| | __ _ _ __ __ _ _ __ ___ __ _ _ __ `| | / / |
- | _ |/ _` | '_ \ / _` | '_ ` _ \ / _` | '_ \ | | / / |
- | | | | (_| | | | | (_| | | | | | | (_| | | | | _| |_ _ ./ / |
- \_| |_/\__,_|_| |_|\__, |_| |_| |_|\__,_|_| |_| \___/ (_) \_/ =========
- __/ |
- |___/""")
- if tries == 3:
- print("""
- +---+
- _ _ __ ______ | |
- | | | | / | |___ / O |
- | |_| | __ _ _ __ __ _ _ __ ___ __ _ _ __ `| | / / | |
- | _ |/ _` | '_ \ / _` | '_ ` _ \ / _` | '_ \ | | / / |
- | | | | (_| | | | | (_| | | | | | | (_| | | | | _| |_ _ ./ / |
- \_| |_/\__,_|_| |_|\__, |_| |_| |_|\__,_|_| |_| \___/ (_) \_/ =========
- __/ |
- |___/""")
- if tries == 4:
- print("""
- +---+
- _ _ __ ______ | |
- | | | | / | |___ / O |
- | |_| | __ _ _ __ __ _ _ __ ___ __ _ _ __ `| | / / /| |
- | _ |/ _` | '_ \ / _` | '_ ` _ \ / _` | '_ \ | | / / |
- | | | | (_| | | | | (_| | | | | | | (_| | | | | _| |_ _ ./ / |
- \_| |_/\__,_|_| |_|\__, |_| |_| |_|\__,_|_| |_| \___/ (_) \_/ =========
- __/ |
- |___/""")
- if tries == 5:
- print("""
- +---+
- _ _ __ ______ | |
- | | | | / | |___ / O |
- | |_| | __ _ _ __ __ _ _ __ ___ __ _ _ __ `| | / / /|\ |
- | _ |/ _` | '_ \ / _` | '_ ` _ \ / _` | '_ \ | | / / |
- | | | | (_| | | | | (_| | | | | | | (_| | | | | _| |_ _ ./ / |
- \_| |_/\__,_|_| |_|\__, |_| |_| |_|\__,_|_| |_| \___/ (_) \_/ =========
- __/ |
- |___/""")
- if tries == 6:
- print("""
- +---+
- _ _ __ ______ | |
- | | | | / | |___ / O |
- | |_| | __ _ _ __ __ _ _ __ ___ __ _ _ __ `| | / / /|\ |
- | _ |/ _` | '_ \ / _` | '_ ` _ \ / _` | '_ \ | | / / / |
- | | | | (_| | | | | (_| | | | | | | (_| | | | | _| |_ _ ./ / |
- \_| |_/\__,_|_| |_|\__, |_| |_| |_|\__,_|_| |_| \___/ (_) \_/ =========
- __/ |
- |___/""")
- if tries == 7:
- print("""
- +---+
- _ _ __ ______ | |
- | | | | / | |___ / O |
- | |_| | __ _ _ __ __ _ _ __ ___ __ _ _ __ `| | / / /|\ |
- | _ |/ _` | '_ \ / _` | '_ ` _ \ / _` | '_ \ | | / / / \ |
- | | | | (_| | | | | (_| | | | | | | (_| | | | | _| |_ _ ./ / |
- \_| |_/\__,_|_| |_|\__, |_| |_| |_|\__,_|_| |_| \___/ (_) \_/ =========
- __/ |
- |___/ Programmer: Zunder Jacob A. Pacis""")
- def space(x):
- for i in range(x):
- print()
- gameStart = True
- while gameStart: #live-game
- hangman(7)
- word = str(input("Enter a word: "))
- wordX = word.upper()
- clue = str(input("Enter a clue: "))
- space(50)
- hidden = [char for char in wordX]
- word1 = [char for char in wordX] # word converted to chars
- for i, char in enumerate(hidden):
- if hidden[i] == " ":
- hidden[i] = " "
- else:
- hidden[i] = "_ "
- gameStart = True
- mistakes = 0
- wrongLetter = []
- while (True):
- # hidden = [char for char in word]
- hidden1 = ''.join(hidden)
- space(50)
- hangman(mistakes)
- print(f"\t\tClue: {clue}")
- renderGraphics()
- if hidden1 == wordX:
- space(50)
- hangman(mistakes)
- renderWon()
- break
- user_input = str(input("Player input > "))
- guessX = user_input.upper()
- if user_input == "/q":
- gameStart = False
- break
- if user_input == "/e":
- break
- if user_input == "print compare":
- print(f"hidden1 = {hidden1}\nwordX = {wordX}")
- if guessX == wordX:
- space(50)
- hidden1 = guessX
- hangman(mistakes)
- renderWon()
- break
- if guessX in wordX:
- for i, char in enumerate(word1):
- if char == guessX:
- # print(f"{guess} = index b{i}")
- hidden[i] = guessX
- print("correct!")
- else:
- # print(f"mali bobo, tries left: {tries}")
- wrongLetter.append(guessX)
- mistakes += 1
- if mistakes == 7:
- space(50)
- hangman(mistakes)
- renderLoss()
- # print(f"gameover!, the word is '{word.upper()}'")
- break
- while (True):
- if gameStart != False:
- user_input = str(input("Console input > "))
- if user_input == "/q":
- gameStart = False
- break
- elif user_input == "/root":
- break
- elif user_input == "/p":
- space(100)
- break
- elif user_input == "/?":
- print("""
- Hangman is a word-guessing game where one player thinks of a word or phrase
- and writes down blank spaces for each letter. Other players take turns guessing
- letters, trying to fill in the blanks. If they guess a letter correctly,
- it's filled in; if not, part of a hangman figure is drawn. The game continues
- until the word is guessed or the hangman is fully drawn. Players win by guessing
- the word or lose if the hangman is completed. It's a fun and challenging game to
- test vocabulary and deduction skills.
- """)
- elif user_input == "/h":
- print("/h - Show commands\n/q - Quit\n/e - Switch to Console (During game)\n/p - Play Again\n/? - Rules")
- else:
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement