Advertisement
lamerlol1994

py

Apr 3rd, 2020
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.16 KB | None | 0 0
  1. import random
  2.  
  3. Hangman_pic = ['''
  4. +----+
  5.      |
  6.      |
  7.      |
  8.     ===''', '''
  9. +----+
  10. 0    |
  11.      |
  12.      |
  13.     ===''', '''
  14. +----+
  15. 0    |
  16. |    |
  17.      |
  18.     ===''', '''
  19. +----+
  20. 0    |
  21. /|    |
  22.      |
  23.     ===''', '''
  24. +----+
  25. 0    |
  26. /|\  |
  27.      |
  28.     ===''', '''
  29. +----+
  30. 0    |
  31. /|\  |
  32. /     |
  33.     ===''', '''
  34. +----+
  35. 0    |
  36. /|\  |
  37. / \  |
  38.     ===''', '''
  39. +----+
  40. [0    |
  41. /|\  |
  42. / \  |
  43.     ===''', '''
  44. +----+
  45. [0]   |
  46. /|\  |
  47. / \  |
  48.     ===''']
  49.    
  50. words ={'colors':'red orange blue green black white silver yellow gold purple pale grey brown'.split(),
  51. 'figures':'cycle corner square triangle rectangle ellipse rhombus hexagon octagon'.split(),
  52. 'fruits':'orange grape pear banana kiwi cherry pineapple apple melon watermelon lime lemon peach mango'.split(),
  53. '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()}
  54. def getRandomWord(wordDict):
  55.     wordKey = random.choice(list(wordDict.keys()))
  56.  
  57.     wordIndex = random.randint(0, len(wordDict[wordKey])-1)
  58.     return wordDict[wordKey][wordIndex]
  59.  
  60. def displayBoard(missedLetters, correctLetters, secretWord):
  61.     print(Hangman_pic[len(missedLetters)])
  62.     print()
  63.  
  64.     print("Ошибочные буквы:", end=' ')
  65.     for letter in missedLetters:
  66.         print(letter, end=' ')
  67.     print()
  68.  
  69.     blanks = '_' * len(secretWord)
  70.  
  71.     for i in range(len(secretWord)):
  72.         if secretWord[i] in correctLetters:
  73.             blanks = blanks[:i] + secretWord[i] + blanks[i + 1:]
  74.  
  75.     for letter in blanks:
  76.         print(letter,end=' ')
  77.         print()
  78.  
  79. def getGuess(alreadyGuessed):
  80.     while True:
  81.         print('Введите букву.')
  82.         guess = input()
  83.         guess = guess.lower()
  84.         if len(guess) != 1:
  85.             print('Введите ОДНУ букву!')
  86.         elif guess in alreadyGuessed:
  87.             print('Вы уже называли эту букву. Назовите другую!')
  88.         elif guess not in 'qwertyuiopasdfghjklzxcvbnm':
  89.             print('Введите БУКВУ!')
  90.         else:
  91.             return guess
  92.  
  93. def playAgain():
  94.     print('Хотите сыграть еще раз? (да или нет')
  95.     return input().lower().startswith('д')
  96.  
  97.  
  98. print("В И С Е Л И Ц А")
  99.  
  100. difficulty = "X"
  101. while difficulty not in ["E", "M", "H"]:
  102.     print("CHoose difficulty lvl: E- Easy , M- middle, H- Heavy ")
  103.     difficulty = input().upper()
  104. if difficulty == "M":
  105.     del Hangman_pic[8]
  106.     del Hangman_pic[7]
  107. if difficulty == "H":
  108.     del Hangman_pic[8]
  109.     del Hangman_pic[7]
  110.     del Hangman_pic[5]
  111.     del Hangman_pic[3]
  112.  
  113. missedLetters = " "
  114. correctLetters = " "
  115. secretWord, secretSet = getRandomWord(words)
  116. gameIsDone = False
  117.  
  118. while True:
  119.     print("Secret word came from list:" + secretSet)
  120.     displayBoard(missedLetters, correctLetters, secretWord)
  121.  
  122.     guess = getGuess(missedLetters + correctLetters)
  123.  
  124.     if guess in secretWord:
  125.         correctLetters = correctLetters + guess
  126.  
  127.         foundAllLetters = True
  128.         for i in range(len(secretWord)):
  129.             if secretWord[i] not in correctLetters:
  130.                 foundAllLetters = False
  131.                 break
  132.         if foundAllLetters:
  133.             print('Да! Секретное слово -"' + secretWord + '"! Вы угадали!')
  134.             gameIsDone = True
  135.     else:
  136.         missedLetters = missedLetters + guess
  137.  
  138.         if len(missedLetters) == len(Hangman_pic) - 1:
  139.             displayBoard(missedLetters, correctLetters, secretWord)
  140.             print("Вы исчерпали все попытки! \n Не угаданно букв:" + str(len(missedLetters)) + "и угаданно букв:" + str(len(correctLetters)) + "Было загаданно слово'" + secretWord + "'.")
  141.             gameIsDone = True
  142.        
  143.         if gameIsDone:
  144.             if playAgain():
  145.                 missedLetters = " "
  146.                 correctLetters = " "
  147.                 gameIsDone = False
  148.                 secretWord, secretSet= getRandomWord(words)
  149.                
  150.             else:
  151.                 break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement