#Tested Version of python:
#Python 3.7.9
#Python 3.9.13
#Python 3.10.7
#Hangman
#----------------------------------
#Imports
#----------------------------------
import time
from turtle import clear
#----------------------------------
#variables
#----------------------------------
word = ''
got_it = False
guesses = [' ']
amountofguesesleft = 9
correct = False
playing = True
hint = ''
hintdone = False
#----------------------------------
#clear the console
#----------------------------------
def clearconsole():
print("\n" * 10)
print("\n" * 10)
print("\n" * 10)
print("\n" * 10)
print("\n" * 10)
print("\n" * 10)
print("\n" * 10)
print("\n" * 10)
print("\n" * 10)
print("\n" * 10)
#----------------------------------
#All the def in the world!
#----------------------------------
def stage0():
print("================")
print("")
print("")
print("")
print("")
print("")
print("")
print("")
print("")
print("================\n")
def stage1():
print("================")
print("")
print("|")
print("|")
print("|")
print("|")
print("|")
print("|")
print("|")
print("================\n")
def stage2():
print("================")
print("____________")
print("|")
print("|")
print("|")
print("|")
print("|")
print("|")
print("|")
print("================\n")
def stage3():
print("================")
print("____________")
print("| |")
print("| |")
print("|")
print("|")
print("|")
print("|")
print("|")
print("================\n")
def stage4():
print("================")
print("____________")
print("| |")
print("| |")
print("| O")
print("|")
print("|")
print("|")
print("|")
print("================\n")
def stage5():
print("================")
print("____________")
print("| |")
print("| |")
print("| O")
print("| |")
print("| |")
print("|")
print("|")
print("================\n")
def stage6():
print("================")
print("____________")
print("| |")
print("| |")
print("| O")
print("| |")
print("| |")
print("| \ ")
print("|")
print("================\n")
def stage7():
print("================")
print("____________")
print("| |")
print("| |")
print("| O")
print("| |")
print("| |")
print("| / \ ")
print("|")
print("================\n")
def stage8():
print("================")
print("____________")
print("| |")
print("| |")
print("| O")
print("| \|")
print("| |")
print("| / \ ")
print("|")
print("================\n")
def stage9():
print("================")
print("____________")
print("| |")
print("| |")
print("| O")
print("| \|/")
print("| |")
print("| / \ ")
print("|")
print("================\n")
def whichdrawring():
global amountofguesesleft
if amountofguesesleft == 8:
stage1()
elif amountofguesesleft == 7:
stage2()
elif amountofguesesleft == 6:
stage3()
elif amountofguesesleft == 5:
stage4()
elif amountofguesesleft == 4:
stage5()
elif amountofguesesleft == 3:
stage6()
elif amountofguesesleft == 2:
stage7()
elif amountofguesesleft == 1:
stage8()
elif amountofguesesleft == 0:
stage9()
else:
stage0()
def start():
global word,got_it,guesses,amountofguesesleft,correct,hint,hintdone
correct = False
while got_it == False:
bad = True
while bad == True:
clearconsole()
whichdrawring()
for letter in word:
if letter.lower() in guesses:
if letter.lower() == " ":
print("/",end=" ")
else:
print(letter,end=" ")
else:
print("_",end=" ")
amountofguesesleft = str(amountofguesesleft)
print("\nYou have " + amountofguesesleft + " chances left.")
amountofguesesleft = int(amountofguesesleft)
option = input("\nWould you like to:\n1. Guess a letter\n2. Guess the word\n3. Get a hint!\n- ")
if option == '1':
guess = input("Guess a letter: ")
guesses.append(guess.lower())
if guess.lower() not in word.lower():
print("better luck next time.")
amountofguesesleft -= 1
bad = False
elif option == '2':
word_guess = input("Guess the word: ")
if word_guess.lower() == word.lower():
correct = True
break
else:
amountofguesesleft -= 1
print("Better luck next time!")
bad = False
elif option == '3':
if hintdone == False:
clearconsole()
print("The hint is: " + hint + "")
time.sleep(3)
amountofguesesleft -= 1
hintdone = True
else:
clearconsole()
print("The hint is: " + hint + "")
time.sleep(3)
else:
clearconsole()
print("Error try again :/")
time.sleep(1)
clearconsole()
if amountofguesesleft == 0:
clearconsole()
break
if correct == True:
clearconsole()
break
got_it = True
correct = True
for letter in word:
if letter.lower() not in guesses:
got_it = False
correct = False
#----------------------------------
#Beginning of actual code aka start
#----------------------------------
clearconsole()
print("==========")
print("Welcome to this hangman code!")
print("Believe it or not but making the drawrings in the code took longer than coding the game itself.")
print("But let's begin!")
print("==========")
while playing == True:
word = input("Please enter the word/phrase you want the player/s to guess!\n- ")
hint = input("You can give the player/s a hint if you wish! If not just press enter and leave blank\n- ")
if hint == '':
hint = "No hint was left"
clearconsole()
start()
if correct == True:
clearconsole()
whichdrawring()
print("You have guessed the word.")
print("The word was '"+ word + "' ")
else:
whichdrawring()
print("You have failed at guessing a word.")
print("0 chances left.")
print("The word was '"+ word + "' ")
bad1 = True
while bad1 is True:
option = input("\nWell now you got two options either:\n1. Play again\n2. Quit\n- ")
if option == '1':
clearconsole()
print("Let's goooo")
time.sleep(1)
bad1 = False
amountofguesesleft = 9
got_it = False
guesses = []
hintdone = False
print(guesses)
elif option == '2':
clearconsole()
print("Well goodbye :/")
time.sleep(1)
quit()
#----------------------------------
#End
#----------------------------------