Ejemplo n.º 1
0
    def _gameloop(self):
        while True:
            self._phrase = choice(list(self.phrases))
            self._phrase_lowered = self._phrase.lower()
            self.state = ['_'] * len(self._phrase)
            self._solve_positions(lambda c: not is_letter(c))
            self.lives = self.phrases[self._phrase]
            self.missed = ""

            display.game_state()
            while True:
                guess = display.ask(Hangman.guess_letter_question,
                                    is_new_letter(self.state, self.missed),
                                    '  Enter one new English letter.').lower()

                if guess in self._phrase_lowered:
                    self._solve_positions(lambda c: guess == c)
                else:
                    self.lives -= 1
                    self.missed += guess

                display.game_state()

                if '_' not in self.state:
                    display.win()
                    break
                elif self.lives == 0:
                    display.lose(self._phrase)
                    break

            if not self._ask_end():
                break
        display.goodbye()
Ejemplo n.º 2
0
    def _gameloop(self):
        while True:
            self._phrase = choice(list(self.phrases))
            self._phrase_lowered = self._phrase.lower()
            self.state = ['_'] * len(self._phrase)
            self._solve_positions(lambda c: not is_letter(c))
            self.lives = self.phrases[self._phrase]
            self.missed = ""

            display.game_state()
            while True:
                guess = display.ask(Hangman.guess_letter_question,
                                    is_new_letter(self.state, self.missed),
                                    '  Enter one new English letter.').lower()

                if guess in self._phrase_lowered:
                    self._solve_positions(lambda c: guess == c)
                else:
                    self.lives -= 1
                    self.missed += guess

                display.game_state()

                if '_' not in self.state:
                    display.win()
                    break
                elif self.lives == 0:
                    display.lose(self._phrase)
                    break

            if not self._ask_end():
                break
        display.goodbye()
Ejemplo n.º 3
0
 def _ask_end(self):
     ans = display.ask(Hangman.play_again_question, is_yn, '  Enter (y/n)')
     return end_if[ans]
Ejemplo n.º 4
0
 def _ask_end(self):
     ans = display.ask(Hangman.play_again_question,
                       is_yn, '  Enter (y/n)')
     return end_if[ans]