overactive

hangman

Jun 13th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.52 KB | None | 0 0
  1. class hangmanGame():
  2.  
  3.     def __init__(self):
  4.         print ("Welcome to Hangman Games")
  5.  
  6.     def Key(self):
  7.         self.keyword = 'alabaster'
  8.         self.start = ('_ '*len(self.keyword))
  9.         print(self.start)
  10.         self.guessedLetters = list(self.start)
  11.  
  12.     def showHangman(self, wrongGuess):
  13.  
  14.         if wrongGuess == 1:
  15.             print( "________      ")
  16.             print( "|      |      ")
  17.             print( "|             ")
  18.             print( "|             ")
  19.             print( "|             ")
  20.             print( "|             ")
  21.  
  22.         elif wrongGuess == 2:
  23.             print( "________      ")
  24.             print( "|      |      ")
  25.             print( "|      O      ")
  26.             print( "|             ")
  27.             print( "|             ")
  28.             print( "|             ")
  29.  
  30.         elif wrongGuess == 3:
  31.             print( "________      ")
  32.             print( "|      |      ")
  33.             print( "|      O      ")
  34.             print( "|      |      ")
  35.             print( "|             ")
  36.             print( "|             ")
  37.  
  38.         elif wrongGuess == 4:
  39.             print( "________      ")
  40.             print( "|      |      ")
  41.             print( "|      O      ")
  42.             print( "|     /|      ")
  43.             print( "|             ")
  44.             print( "|             ")
  45.  
  46.         elif wrongGuess == 5:
  47.             print( "________      ")
  48.             print( "|      |      ")
  49.             print( "|      O      ")
  50.             print( "|     /|\    ")
  51.             print( "|             ")
  52.             print( "|             ")
  53.         elif wrongGuess == 6:
  54.             print( "________      ")
  55.             print( "|      |      ")
  56.             print( "|      O      ")
  57.             print( "|     /|\    ")
  58.             print( "|       \    ")
  59.             print( "|             ")
  60.         else:
  61.             print( "________      ")
  62.             print( "|      |      ")
  63.             print( "|      O      ")
  64.             print( "|     /|\    ")
  65.             print( "|     / \    ")
  66.             print( "|             ")
  67.  
  68.    
  69.  
  70.  
  71.     def Guess(self):
  72.         guesses = 0
  73.        
  74.         while guesses < 7:
  75.             print("Write the letter:")
  76.            
  77.             letter = input()
  78.             if len(letter)>1:
  79.                 print("Don't cheat! Only one letter:")
  80.                 letter = input()
  81.            
  82.  
  83.             letterPos =[pos for pos, char in enumerate(self.keyword) if char == letter] #nie do konca kumam co tu sie dzieje
  84.  
  85.  
  86.             if letter in self.keyword:
  87.                
  88.                 for i in range (len(letterPos)):
  89.                     self.guessedLetters[letterPos[i]*2]=letter
  90.                
  91.                 self.guessedLettersStr = ("".join(self.guessedLetters))
  92.                 print(self.guessedLettersStr)
  93.            
  94.             elif letter not in self.keyword :
  95.                
  96.                 guesses = guesses +1
  97.                 self.showHangman(guesses)
  98.                 print(self.guessedLettersStr)
  99.  
  100.             if guesses == 7:
  101.                 print("game over")
  102.  
  103.             if self.guessedLettersStr.find('_') == -1:
  104.                 print("You won!")
  105.                 break
  106.                
  107.  
  108.        
  109.  
  110. def Game():
  111.     hang=hangmanGame()
  112.     hang.Key()
  113.     hang.Guess()
  114.  
  115. Game()
Advertisement
Add Comment
Please, Sign In to add comment