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_wordsMatch(self): self.assertFalse(replay.wordsMatch("hello", "*****")) #self.assertFalse(replay.wordsMatch(None, None)) self.assertTrue(replay.wordsMatch("hello", "hello")) self.assertFalse(replay.wordsMatch("Hello", "hello")) self.assertFalse(replay.wordsMatch("hello", "he**o"))