Last active
December 26, 2019 12:52
-
-
Save ZenulAbidin/6e564f630fa274dcdedd3ef3b05860f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
#++++++++ 1 | |
No_man = ['________', | |
'| |', | |
'| ', | |
'| ', | |
'| ', | |
'| ', | |
'| '] | |
#======== | |
Head_man = ['________', | |
'| |', | |
'| O', | |
'| ', | |
'| ', | |
'| ', | |
'| '] | |
Body_man = ['________', | |
'| |', | |
'| O', | |
'| |', | |
'| ', | |
'| ', | |
'| '] | |
Body1_man= ['________', | |
'| |', | |
'| O', | |
'| |', | |
'| |', | |
'| ', | |
'| '] | |
Body2_man= ['________', | |
'| |', | |
'| O', | |
'| |', | |
'| |', | |
'| |', | |
'| '] | |
Right_man= ['________', | |
'| |', | |
'| O', | |
'| |', | |
'| |\ ', | |
'| |', | |
'| '] | |
Left_man = ['________', | |
'| |', | |
'| O', | |
'| |', | |
'| /|\ ', | |
'| |', | |
'| '] | |
Right_leg_man= ['________', | |
'| |', | |
'| O', | |
'| |', | |
'| /|\ ', | |
'| |', | |
'| \ '] | |
Full_man = ['________', | |
'| |', | |
'| O', | |
'| |', | |
'| /|\ ', | |
'| |', | |
'| / \ '] | |
#________ 2 | |
#Full_Body= [(Head_man), | |
# (Body_man), | |
# (Body1_man), | |
# (Body2_man), | |
# (Right_man), | |
# (Left_man), | |
# (Right_leg_man), | |
# (Full_man)] | |
#-------- | |
#++++++++ | |
Full_Body= [No_man, | |
Head_man, | |
Body_man, | |
Body1_man, | |
Body2_man, | |
Right_man, | |
Left_man, | |
Right_leg_man, | |
Full_man] | |
#======== | |
def getAvailableLetters(lettersGuessed): | |
''' | |
lettersGuessed: list, what letters have been guessed so far | |
returns: string, comprised of letters that represents what letters have not | |
yet been guessed. | |
''' | |
import string | |
fullstring = string.ascii_lowercase | |
lettersLeft = '' | |
for letter in fullstring: | |
if letter not in lettersGuessed: | |
lettersLeft = lettersLeft + letter | |
return lettersLeft | |
def getGuessedWord(secretWord, lettersGuessed): | |
''' | |
secretWord: string, the word the user is guessing | |
lettersGuessed: list, what letters have been guessed so far | |
returns: string, comprised of letters and underscores that represents | |
what letters in secretWord have been guessed so far. | |
''' | |
wordGuessed = '' | |
for letter in secretWord: | |
if letter in lettersGuessed: | |
wordGuessed = wordGuessed + letter | |
else: | |
wordGuessed = wordGuessed + '_ ' | |
return wordGuessed | |
def isWordGuessed(secretWord, lettersGuessed): | |
''' | |
secretWord: string, the word the user is guessing | |
lettersGuessed: list, what letters have been guessed so far | |
returns: boolean, True if all the letters of secretWord are in lettersGuessed; | |
False otherwise | |
''' | |
numCorrect = 0 | |
for letter in secretWord: | |
if letter in lettersGuessed: | |
numCorrect += 1 | |
else: | |
return False | |
return True | |
def HangMan(secretWord): | |
guessesLeft = 8 | |
#++++++++ | |
bodyindex = 0 | |
#======== | |
lettersGuessed =[] | |
print('Welcome to the game Hangman!\n') | |
#________ 3 | |
# print('I am thinking of a word that is ' + str(len(random.choice(secretWord))) + ' letters long.\n\n' ) | |
#-------- | |
#++++++++ | |
print('I am thinking of a word that is ' + str(len(secretWord)) + ' letters long.\n\n' ) | |
#======== | |
while guessesLeft > 0: | |
if isWordGuessed(secretWord, lettersGuessed): | |
#________ 4 | |
# return print('Congratulations, you won!') | |
#-------- | |
#++++++++ | |
print('Congratulations, you won!') | |
return | |
#======== | |
print('You have ' + str(guessesLeft) + ' guesses left.') | |
print('_________________________________Available Letters: ' + getAvailableLetters(lettersGuessed)) | |
user_input = input('Please guess a letter: ') | |
user_input = str(user_input) | |
user_input = user_input.lower() | |
if user_input not in lettersGuessed: | |
lettersGuessed.append(user_input) | |
#________ | |
# print(scroll(Full_Body)) | |
#-------- | |
#++++++++ 5 | |
if user_input not in secretWord: | |
bodyindex += 1 | |
print('\n'.join(Full_Body[bodyindex])) | |
#======== | |
if user_input in secretWord: | |
print("Good guess: " + getGuessedWord(secretWord, lettersGuessed)) | |
print('-----------') | |
else: | |
print("Oops! That letter is not in my word: " + getGuessedWord(secretWord, lettersGuessed)) | |
print('-----------') | |
guessesLeft -= 1 | |
else: | |
print("Oops! You've already guessed that letter: " + getGuessedWord(secretWord, lettersGuessed)) | |
print('-----------') | |
#________ | |
# return print("Sorry, you ran out of guesses. The word was " + str(secretWord)) | |
#-------- | |
#++++++++ | |
print("Sorry, you ran out of guesses. The word was " + str(secretWord)) | |
return | |
#======== | |
#________ | |
#hangman =[('stackoverflow'), | |
# ('aaron'), | |
# ('bob'), | |
# ('storm'), | |
# ('fortnite'), | |
# ('yoda'), | |
# ('dog'), | |
# ('computer'), | |
# ('return'), | |
# ('hangman'), | |
# ('scarce'), | |
# ('smell'), | |
# ('sneeze'), | |
# ('needle'), | |
# ('stone'), | |
# ('dry'), | |
# ('cobweb'), | |
# ('blue'), | |
# ('green'), | |
# ('yellow'), | |
# ('purple'), | |
# ('black'), | |
# ('white'), | |
# ('python'), | |
# ('doctor'), | |
# ('brother'), | |
# ('pie'), | |
# ('explode'), | |
# ('laugh'), | |
# ('military'), | |
# ('chop'), | |
# ('shop'), | |
# ('secret'), | |
# ('input'), | |
# ('guess'), | |
# ('class'), | |
# ('teacher'), | |
# ('box'), | |
# ('dragon'), | |
# ('light'), | |
# ('buket'), | |
# ('pipe'), | |
# ('coffee'), | |
# ('mug'), | |
# ('faith'), | |
# ('cup'), | |
# ('blanket'), | |
# ('locker'), | |
# ('brick'), | |
# ('siren'), | |
# ('bottle'), | |
# ('water'), | |
# ('sticker'), | |
# ('time'), | |
# ('use')] | |
#-------- | |
#++++++++ | |
hangman =['stackoverflow', | |
'aaron', | |
'bob', | |
'storm', | |
'fortnite', | |
'yoda', | |
'dog', | |
'computer', | |
'return', | |
'hangman', | |
'scarce', | |
'smell', | |
'sneeze', | |
'needle', | |
'stone', | |
'dry', | |
'cobweb', | |
'blue', | |
'green', | |
'yellow', | |
'purple', | |
'black', | |
'white', | |
'python', | |
'doctor', | |
'brother', | |
'pie', | |
'explode', | |
'laugh', | |
'military', | |
'chop', | |
'shop', | |
'secret', | |
'input', | |
'guess', | |
'class', | |
'teacher', | |
'box', | |
'dragon', | |
'light', | |
'buket', | |
'pipe', | |
'coffee', | |
'mug', | |
'faith', | |
'cup', | |
'blanket', | |
'locker', | |
'brick', | |
'siren', | |
'bottle', | |
'water', | |
'sticker', | |
'time', | |
'use'] | |
#======== | |
while input("Shall we play a game? [y|n] ") == 'y': | |
#+++++++++ 6 | |
secretWord = random.choice(hangman) | |
#========= | |
HangMan(secretWord) | |
else: | |
print("Ok, GoodBye") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment