def hangman(): word_to_guess, word = replay.getWord() # word is the unaltered word wrong = 0 end_game = True while end_game or wrong > 6: # 6 is the number of wrong guess for the game ends replay.gallows(wrong) print word_to_guess # used for test remove when finished users_guess = raw_input("Pick a letter you think the word contains:") if users_guess.isalpha(): wrong_increment = 0 wrong_increment, word_to_guess = replay.match(users_guess, word, word_to_guess) wrong += wrong_increment # not very clear on what it is for else: print "Invalid input!" wrong += 1 victory = replay.wordsMatch(word, word_to_guess) if wrong == 6: replay.gallows(wrong) print word_to_guess print "You lose" end_game = False elif victory: print "You won!\n" end_game = False
def test_match(self): self.assertEqual(replay.match("a", "hello", "*****"), (1, "*****")) self.assertEqual(replay.match("e", "hello", "*****"), (0, "*e***"))