Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def Title():
- print("""
- __ __ ___ .__ __. _______ .___ ___. ___ .__ __.
- | | | | / \ | \ | | / _____|| \/ | / \ | \ | |
- | |__| | / ^ \ | \| | | | __ | \ / | / ^ \ | \| |
- | __ | / /_\ \ | . ` | | | |_ | | |\/| | / /_\ \ | . ` |
- | | | | / _____ \ | |\ | | |__| | | | | | / _____ \ | |\ |
- |__| |__| /__/ \__\ |__| \__| \______| |__| |__| /__/ \__\ |__| \__|
- """)
- def Win():
- print("""
- ____ ____ __ ______ .___________. ______ .______ ____ ____
- \ \ / / | | / || | / __ \ | _ \ \ \ / /
- \ \/ / | | | ,----'`---| |----`| | | | | |_) | \ \/ /
- \ / | | | | | | | | | | | / \_ _/
- \ / | | | `----. | | | `--' | | |\ \----. | |
- \__/ |__| \______| |__| \______/ | _| `._____| |__|
- """)
- def Lose():
- print("""
- _______ _______ _______ _______ ___ .___________.
- | \ | ____|| ____|| ____| / \ | |
- | .--. || |__ | |__ | |__ / ^ \ `---| |----`
- | | | || __| | __| | __| / /_\ \ | |
- | '--' || |____ | | | |____ / _____ \ | |
- |_______/ |_______||__| |_______/__/ \__\ |__|
- """)
- def Zero():
- print("""
- 0000000000000
- 0 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- """)
- def One():
- print("""
- 0000000000000
- 0 0
- 0 1
- 0 1 1
- 0 1
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- """)
- def Two():
- print("""
- 0000000000000
- 0 0
- 0 1
- 0 1 1
- 0 1
- 0 2
- 0 2
- 0 2
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- """)
- def Three():
- print("""
- 0000000000000
- 0 0
- 0 1
- 0 1 1
- 0 1
- 0 32
- 0 3 2
- 0 3 2
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- """)
- def Four():
- print("""
- 0000000000000
- 0 0
- 0 1
- 0 1 1
- 0 1
- 0 324
- 0 3 2 4
- 0 3 2 4
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- """)
- def Five():
- print("""
- 0000000000000
- 0 0
- 0 1
- 0 1 1
- 0 1
- 0 324
- 0 3 2 4
- 0 3 2 4
- 0 5
- 0 5
- 0 5
- 0 5
- 0
- 0
- 0
- """)
- def Six():
- print("""
- 0000000000000
- 0 0
- 0 1
- 0 1 1
- 0 1
- 0 324
- 0 3 2 4
- 0 3 2 4
- 0 5 6
- 0 5 6
- 0 5 6
- 0 5 6
- 0
- 0
- 0
- """)
- def Clear():
- for i in range(50):
- print("\n")
- def Replay():
- print("\n\nWould you like to play again?")
- sleep(2)
- choice = input("-(Y)es\n-(N)o\n")
- sleep(2)
- if choice.lower() == "y":
- choice = input("\nWould you like to play...\n-(O)ne player\n-(T)wo player\n")
- sleep(2)
- if choice.lower() == "o":
- Clear()
- GameIntro(1)
- elif choice.lower() == "t":
- Clear()
- GameIntro(2)
- else:
- print("You have not entered a valid option, please try again.")
- Replay()
- elif choice.lower() == "n":
- sleep(2)
- print("\nThanks for playing hang man. Good bye.")
- sleep(2)
- quit()
- else:
- print("\nYou have not entered a valid option, please try again.")
- Replay()
- def OnePlayer():
- print("A random word is being chosen for you...")
- randomwords = ["dancing","cheering","swinging","jumping","partying","blasting","crafting","working","jumping","programming","nerding","hopping","playing"]
- word = choice(randomwords)
- return word
- def TwoPlayer():
- validcount = 0
- validword = False
- while validword == False:
- word = getpass("One player must enter a word for the other player to guess. Don't worry, what you type will not be visible on the screen.\n").lower()
- if len(word) < 5:
- sleep(1)
- print("Your word must be 4 letters or more in length. Please try again.")
- word = input("One player must enter a word for the other player to guess. Don't worry, what you type will not be visible on the screen.\n").lower()
- sleep(1)
- for char in word:
- if char.isalpha() != True:
- if char == " ":
- validcount += 1
- else:
- validcount += 1
- if validcount < len(word):
- validcount = 0
- sleep(1)
- print("\nYour word can only contain letters and spaces. Please try again.\n")
- sleep(1)
- else:
- validword = True
- return word
- def GameIntro(players):
- if players == 1:
- word = OnePlayer()
- elif players == 2:
- word = TwoPlayer()
- else:
- print("A critical error has occurred. Computer is sorry.")
- sleep(2)
- Clear()
- print("\nNow that the word has been determined it's time to begin the game.")
- sleep(2)
- print("You must now begin guess either a single character or the entire word.")
- sleep(2)
- print("\n\nEach guess you make incorrectly will take one of your lives away and put you one step closer to killing the hangman.")
- sleep(2)
- print("Here is your starting point...")
- sleep(2)
- One()
- sleep(8)
- Game(word)
- def Game(word):
- Clear()
- counter = 0
- blanktext = []
- correctguesses = []
- incorrectguesses = []
- totalguesses = 0
- guess = ""
- for char in word:
- blanktext.append("_")
- blanktext.append(" ")
- print("There are "+str(len(word))+" characters in the word.")
- sleep(1)
- print("".join(blanktext))
- while totalguesses < 6:
- validcount = 0
- validguess = False
- guess = input("\nPlease guess either a single character or a word.\n")
- sleep(1)
- while validguess == False:
- for char in guess:
- if char.isalpha() == False:
- if char == " ":
- validcount += 1
- else:
- validcount += 1
- if validcount < len(guess):
- print("You have not made a valid guess, please only enter letters or spaces")
- sleep(1)
- guess = input("\nPlease guess either a single character or a word.\n")
- sleep(1)
- else:
- validguess = True
- Clear()
- if len(guess) == 1:
- #evaluation of single character within word-string
- if word.lower().find(guess.lower()) >= 0:
- if guess.lower() not in correctguesses:
- counter += 1
- indexcount = 0
- for char in word:
- if char.lower() == guess.lower():
- blanktext[indexcount*2] = guess
- correctguesses.append(guess.lower())
- indexcount += 1
- else:
- indexcount += 1
- if "_" not in blanktext:
- #Game Won
- Win()
- sleep(2)
- print("You got it right.")
- sleep(2)
- print("\nThe word was: "+word)
- sleep(2)
- print("\nTotal guesses made:"+str(counter))
- sleep(2)
- Replay()
- else:
- print("\nYou may not re-use guesses.")
- else:
- #lose life mechanic
- if guess.lower() not in incorrectguesses:
- totalguesses += 1
- counter += 1
- incorrectguesses.append(guess.lower())
- print("\nYou have used up an incorrect guess, the hangman suffers.")
- sleep(2)
- if totalguesses == 1:
- One()
- elif totalguesses == 2:
- Two()
- elif totalguesses == 3:
- Three()
- elif totalguesses == 4:
- Four()
- elif totalguesses == 5:
- Five()
- else:
- print("\nYou may not re-use guesses.")
- sleep(2)
- print("\nLetters left: "+("".join(blanktext)))
- print("Incorrect guesses used: "+(",".join(incorrectguesses)))
- else:
- #evaluation of entire string compared to word-string
- if guess.lower() == word.lower():
- counter += 1
- Win()
- sleep(2)
- print("You got it right.")
- sleep(2)
- print("\nThe word was: "+word)
- sleep(2)
- print("\nTotal guesses made: "+str(counter))
- sleep(2)
- Replay()
- else:
- if guess.lower() not in incorrectguesses:
- counter += 1
- totalguesses += 1
- incorrectguesses.append(guess.lower())
- print("\nYou have used up an incorrect guess, the hangman suffers.")
- sleep(2)
- if totalguesses == 1:
- One()
- elif totalguesses == 2:
- Two()
- elif totalguesses == 3:
- Three()
- elif totalguesses == 4:
- Four()
- elif totalguesses == 5:
- Five()
- print("\nLetters left: "+("".join(blanktext)))
- print("Incorrect guesses used: "+(",".join(incorrectguesses)))
- Six()
- sleep(1)
- Lose()
- sleep(2)
- print("\nToo bad, you let the hang man die. Shame on you...")
- sleep(2)
- print("\nTotal guesses made: "+str(counter))
- sleep(2)
- Replay()
- def Menu():
- Title()
- print("In this Python-based version of the classic game Hangman you are able to choose between playing against someone else or playing against the computer.\n")
- sleep(2)
- choice = input("Would you like to...\n-Play against the (c)omputer.\n-Play against another (p)erson.\n")
- sleep(1)
- while choice.lower() != "c" and choice.lower() != "p":
- print("\nYou have not entered a valid option\n")
- sleep(1)
- choice = input("Would you like to...\n-Play against the (c)omputer.\n-Play against another (p)erson.\n")
- print("")
- if choice == "c":
- GameIntro(1)
- elif choice =="p":
- GameIntro(2)
- else:
- print("A critical error has occurred. Computer is sorry.")
- def Main():
- Menu()
- from time import sleep
- from random import choice
- from getpass import getpass
- Main()
Advertisement
Add Comment
Please, Sign In to add comment