Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- Hangman_pic = ['''
- +----+
- |
- |
- |
- ===''', '''
- +----+
- 0 |
- |
- |
- ===''', '''
- +----+
- 0 |
- | |
- |
- ===''', '''
- +----+
- 0 |
- /| |
- |
- ===''', '''
- +----+
- 0 |
- /|\ |
- |
- ===''', '''
- +----+
- 0 |
- /|\ |
- / |
- ===''', '''
- +----+
- 0 |
- /|\ |
- / \ |
- ===''', '''
- +----+
- [0 |
- /|\ |
- / \ |
- ===''', '''
- +----+
- [0] |
- /|\ |
- / \ |
- ===''']
- words ={'colors':'red orange blue green black white silver yellow gold purple pale grey brown'.split(),
- 'figures':'cycle corner square triangle rectangle ellipse rhombus hexagon octagon'.split(),
- 'fruits':'orange grape pear banana kiwi cherry pineapple apple melon watermelon lime lemon peach mango'.split(),
- 'animals':'zebra horse dolphines dog cat tiger lion wolf sqrel piget crown egale rabit gorila cow orex goat gus rino mouse rat fox mul wheal owl'.split()}
- def getRandomWord(wordDict):
- wordKey = random.choice(list(wordDict.keys()))
- wordIndex = random.randint(0, len(wordDict[wordKey])-1)
- return wordDict[wordKey][wordIndex]
- def displayBoard(missedLetters, correctLetters, secretWord):
- print(Hangman_pic[len(missedLetters)])
- print()
- print("Ошибочные буквы:", end=' ')
- for letter in missedLetters:
- print(letter, end=' ')
- print()
- blanks = '_' * len(secretWord)
- for i in range(len(secretWord)):
- if secretWord[i] in correctLetters:
- blanks = blanks[:i] + secretWord[i] + blanks[i + 1:]
- for letter in blanks:
- print(letter,end=' ')
- print()
- def getGuess(alreadyGuessed):
- while True:
- print('Введите букву.')
- guess = input()
- guess = guess.lower()
- if len(guess) != 1:
- print('Введите ОДНУ букву!')
- elif guess in alreadyGuessed:
- print('Вы уже называли эту букву. Назовите другую!')
- elif guess not in 'qwertyuiopasdfghjklzxcvbnm':
- print('Введите БУКВУ!')
- else:
- return guess
- def playAgain():
- print('Хотите сыграть еще раз? (да или нет')
- return input().lower().startswith('д')
- print("В И С Е Л И Ц А")
- difficulty = "X"
- while difficulty not in ["E", "M", "H"]:
- print("CHoose difficulty lvl: E- Easy , M- middle, H- Heavy ")
- difficulty = input().upper()
- if difficulty == "M":
- del Hangman_pic[8]
- del Hangman_pic[7]
- if difficulty == "H":
- del Hangman_pic[8]
- del Hangman_pic[7]
- del Hangman_pic[5]
- del Hangman_pic[3]
- missedLetters = " "
- correctLetters = " "
- secretWord, secretSet = getRandomWord(words)
- gameIsDone = False
- while True:
- print("Secret word came from list:" + secretSet)
- displayBoard(missedLetters, correctLetters, secretWord)
- guess = getGuess(missedLetters + correctLetters)
- if guess in secretWord:
- correctLetters = correctLetters + guess
- foundAllLetters = True
- for i in range(len(secretWord)):
- if secretWord[i] not in correctLetters:
- foundAllLetters = False
- break
- if foundAllLetters:
- print('Да! Секретное слово -"' + secretWord + '"! Вы угадали!')
- gameIsDone = True
- else:
- missedLetters = missedLetters + guess
- if len(missedLetters) == len(Hangman_pic) - 1:
- displayBoard(missedLetters, correctLetters, secretWord)
- print("Вы исчерпали все попытки! \n Не угаданно букв:" + str(len(missedLetters)) + "и угаданно букв:" + str(len(correctLetters)) + "Было загаданно слово'" + secretWord + "'.")
- gameIsDone = True
- if gameIsDone:
- if playAgain():
- missedLetters = " "
- correctLetters = " "
- gameIsDone = False
- secretWord, secretSet= getRandomWord(words)
- else:
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement