from random import choice as choice # Prints the rules of the hangman game def rules(): print("Welcome! Here are the rules of hang man: ") print("\n1. You have 6 chances to guess the correct word presented.") print("\n2. If you can guess the word correct, you win!") print("\n3. If you run out of chances, however, you lose...") print("\n4. And if you want to guess the word type in 'solve'") print("\n5. Do not use capital letters and have fun!") rules() #Import sprites later HANGMAN_PICS = [''' +---+ | | | ===''', ''' +---+ O | | | ===''', ''' +---+ O | | | | ===''', ''' +---+ O | /| | | ===''', ''' +---+ O | /|\ | | ===''', ''' +---+ O | /|\ | / | ===''', ''' +---+ O | /|\ | / \ | ==='''] # Selection of words so far # TODO: Add more words Words = Words = ["chimera", "wyrm", "griffin", "pegasus", "hippocampus", "merman", "foot", "adviser", "whole", "falsify", "fashion", "cucumber", "rob", "grandmother", "worm", "pumpkin", "appetite", "monstrous", "taxi", "of", "contraction", "can", "joint", "church", "complete", "occupy", "demonstrate", "frighten", "war", "sense", "wagon", "poison", "far", "mislead", "mass", "spectrum", "industry", "onion", "meadow", "blame", "democratic", "breakfast", "decoration", "addition", "snarl", "husband", "smell", "surprise", "instruction", "tourist", "rotate", "circulation", "bar", "uncertainty", "speed", "permanent", "wine", "absolute"] # Type solve to solve the word solve = ["solve"] # Letters of the word put in a list letters = [] # Correct letters c_Letters = [] # Incorrect letters w_Letters = [] # Displays the letters and underscores display = [] # def addDisplay(): # for thing in display: # print(thing) # TODO: make a randomizer that can have buffs or debuffs # Makes the hangman game a function so it can be called later if you want # to play again def Hangman(): # Clears the lists so they can be used again c_Letters.clear() w_Letters.clear() letters.clear() # Randomizes the words so each time you play it is different word = choice (Words) # Gives how many underscores there are in the word answer = len(word) # Amount of tries user gets chances = 6 # Makes the underscores for the word display.append("_ " * answer) for letter in word: letters.append(letter) # Makes the game run until the user runs out of chances while chances > 0: # Puts underscores to display how many letters are in the word as well as # the number # of letters for thing in display: print(thing) if chances == 6: print(HANGMAN_PICS[0]) elif chances == 5: print(HANGMAN_PICS[1]) elif chances == 4: print(HANGMAN_PICS[2]) elif chances == 3: print(HANGMAN_PICS[3]) elif chances == 2: print(HANGMAN_PICS[4]) elif chances == 1: print(HANGMAN_PICS[5]) else: print(HANGMAN_PICS[6]) print("\nThe word has " + str(len(word)) + " letter(s)") guess = input("Try and guess a letter in the word: ") if guess in word: if guess not in c_Letters: print("Correct!") c_Letters.append(guess) print("\nCorrect letters: " + str(c_Letters)) print("Wrong letters: " + str(w_Letters)) # TODO: find a way to replace the underscores with the correct letter if guess in letters: for i in range(len(letters)): if letters[i] == guess: display.remove(display[i]) display.insert(i, guess) else: print("You already guessed that letter!") print("\nCorrect letters: " + str(c_Letters)) print("Wrong letters: " + str(w_Letters)) #Allows user to solve the word elif guess in solve: fullWord = input("What is the full word?: ") if word == fullWord: print("You Win!") break else: print("Wrong guess! Try again!" + "\n") chances -= 1 print("\nYou have " + str(chances) + " guesses left!") print("Correct letters: " + str(c_Letters)) print("Wrong letters: " + str(w_Letters)) elif len(guess) > 1: print("\nYou can only guess one letter at a time!") print("If you want to solve type 'solve'.") print("\nYou have " + str(chances) + " guesses left!") print("Correct letters: " + str(c_Letters)) print("Wrong letters: " + str(w_Letters)) elif guess not in word: if guess not in w_Letters: print("Wrong...") w_Letters.append(guess) chances -= 1 if chances == 0: print(HANGMAN_PICS[6]) print("You Lose!") print("The word was " + word) break print("\nYou have " + str(chances) + " guesses left!") print("Correct letters: " + str(c_Letters)) print("Wrong letters: " + str(w_Letters)) else: print(guess + " has already been guessed!") print("\nYou have " + str(chances) + " guesses left!") print("Correct letters: " + str(c_Letters)) print("Wrong letters: " + str(w_Letters)) else: print("Invalid input" + "\n") chances -= 1 print("You have " + str(chances) + " guesses left!") if chances == 0: print("\nYou lose...") print("Your word was " + str(word) + ".") break #TODO: create the hangman guy #TODO: create the winning screen #TODO: create the losing screen #Makes sure the user wants to play print("\nAre you ready to play?") ready = input() if "y" in ready or "f" in ready: Hangman() else: print("Do you need to see the rules?") ready = input() if "y" in ready or "f" in ready: rules() else: print("You don't want to play?") ready = input() if "y" in ready or "f" in ready: Hangman() else: print("Ya know what, I dont care. You're playing anyways." + "\n") Hangman() # asks if the user wants to play again and if so the hangman function runs # again while True: restart = input("\nDo you want to play again?") if "y" in restart or "f" in restart: print("Do you need to see the rules?") ready = input() if "y" in ready or "f" in ready: rules() else: Hangman() else: print("\nGet lost, loser!") break