コード例 #1
0
ファイル: ahorcado.py プロジェクト: ingtiti/ahorcado
def play_again():
    """
    Returns True si el jugador desea repetir juego, Falso de lo contrario
    """

    xprint('Quieres jugar otra vez? (si o no)')
    return input().lower() == 'si'
コード例 #2
0
    def _check_win(self):
        """Returns True if the user has won, False otherwise.
        Checks if the user has correctly guessed the secret word.
        """

        for i in range(len(self._secret_word)):
            if self._secret_word[i] not in self._correct_letters:
                return False

        xprint('Yes! The secret word is "{0}"! '
               'You have won!'.format(self._secret_word))

        return True
コード例 #3
0
ファイル: gallows.py プロジェクト: Chennaipy/hangman
    def _check_win(self):
        """Returns True if the user has won, False otherwise.

        Checks if the user has correctly guessed the secret word.
        """

        for i in range(len(self._secret_word)):
            if self._secret_word[i] not in self._correct_letters:
                return False

        xprint('Yes! The secret word is "{0}"! '
               'You have won!'.format(self._secret_word))

        return True
コード例 #4
0
ファイル: ahorcado.py プロジェクト: ingtiti/ahorcado
    def _check_win(self):
        """
        Returns True si gano el jugador, de lo contrario False.
        Valida que el jugador adivino correctamente la palabra.
        """

        for i in range(len(self._palabra_secreta)):
            if self._palabra_secreta[i] not in self._letra_correcta:
                return False

        xprint('De lujo! La palabra secreta es "{0}"! ' #{} se substituye por valor de 'self._palabra_secreta'
               'Tu ganaste!'.format(self._palabra_secreta))

        return True
コード例 #5
0
ファイル: gallows.py プロジェクト: Chennaipy/hangman
    def run(self):
        """Initialises the game play and coordinates the game activities."""

        xprint('H A N G M A N')

        while not self._game_is_done:
            self._display_board()

            guessed_letters = self._missed_letters + self._correct_letters
            guess = self._get_guess(guessed_letters)

            if guess in self._secret_word:
                self._correct_letters = self._correct_letters + guess
                self._game_is_done = self._check_win()
            else:
                self._missed_letters = self._missed_letters + guess
                self._game_is_done = self._check_lost()
コード例 #6
0
ファイル: ahorcado.py プロジェクト: ingtiti/ahorcado
    def run(self):
        """Inicio de juego y reset de valores iniciales."""

        xprint('A H O R C A D O')

        while not self._juego_listo:
            self._display_board()

            letra_elegida = self._letra_error + self._letra_correcta
            guess = self._que_adivino(letra_elegida)

            if guess in self._palabra_secreta:
                self._letra_correcta = self._letra_correcta + guess
                self._juego_listo = self._check_win()
            else:
                self._letra_error = self._letra_error + guess
                self._juego_listo = self._check_lost()
コード例 #7
0
    def run(self):
        """Initialises the game play and coordinates the game activities."""

        xprint('H A N G M A N')

        while not self._game_is_done:
            self._display_board()

            guessed_letters = self._missed_letters + self._correct_letters
            guess = self._get_guess(guessed_letters)

            if guess in self._secret_word:
                self._correct_letters = self._correct_letters + guess
                self._game_is_done = self._check_win()
            else:
                self._missed_letters = self._missed_letters + guess
                self._game_is_done = self._check_lost()
コード例 #8
0
    def run(self):
        """Initialises the game play and coordinates the game activities."""

        xprint('H A N G M A N')
        #While the game is not done it will display the board
        while not self._game_is_done:
            self._display_board()
            #shows missed and guesses letters
            guessed_letters = self._missed_letters + self._correct_letters
            guess = self._get_guess(guessed_letters)
            #if the guess is in the secret word add the guess to the correct letters list
            if guess in self._secret_word:
                self._correct_letters = self._correct_letters + guess
                self._game_is_done = self._check_win()
#if the guess is not in the secret word add the letters to the missed letters list
            else:
                self._missed_letters = self._missed_letters + guess
                self._game_is_done = self._check_lost()
コード例 #9
0
    def _check_lost(self):
        """Returns True if the user has lost, False otherwise.
        Alerts the user if all his chances have been used, without
        guessing the secret word.
        """

        if len(self._missed_letters) == len(HANGMANPICS) - 1:
            self._display_board()

            missed = len(self._missed_letters)
            correct = len(self._correct_letters)
            word = self._secret_word
            xprint('You have run out of guesses!')
            xprint('After {0} missed guesses and {1} correct guesses, '
                   'the word was "{2}"'.format(missed, correct, word))

            return True

        return False
コード例 #10
0
ファイル: ahorcado.py プロジェクト: ingtiti/ahorcado
    def _check_lost(self):
        """Returns True si el jugador perdio, False de lo contrario
        Da aviso al jugador que sus oportunidades terminaron y no
        logro adivinar la palabra.
        """

        if len(self._letra_error) == len(QUEMANDOSE) - 1:
            self._display_board()

            missed = len(self._letra_error) #contador de errores
            correct = len(self._letra_correcta) #contador de aciertos
            word = self._palabra_secreta #palabra secreta
            xprint('Lo siento, no mas oportunidades!')
            xprint('Despues de {0} fallos y {1} aciertos, '
                   'la palabra era: "{2}"'.format(missed, correct, word))
            #{} son substituidos por los valores de variables 'missed, correct, word'

            return True

        return False
コード例 #11
0
ファイル: gallows.py プロジェクト: Chennaipy/hangman
    def _check_lost(self):
        """Returns True if the user has lost, False otherwise.

        Alerts the user if all his chances have been used, without
        guessing the secret word.
        """

        if len(self._missed_letters) == len(HANGMANPICS) - 1:
            self._display_board()

            missed = len(self._missed_letters)
            correct = len(self._correct_letters)
            word = self._secret_word
            xprint('You have run out of guesses!')
            xprint('After {0} missed guesses and {1} correct guesses, '
                   'the word was "{2}"'.format(missed, correct, word))

            return True

        return False
コード例 #12
0
    def _get_guess(self, already_guessed):
        """Gets the input from the user.
        Makes sure that the input entered is a letter and
        the letter entered is not already guessed by the user.
        """

        while True:
            xprint('Guess a letter.')
            guess = input().lower()
            if len(guess) != 1:
                xprint('Please enter a single letter.')
            elif guess in already_guessed:
                xprint('You have already guessed that letter. Choose again.')
            elif guess not in 'abcdefghijklmnopqrstuvwxyz':
                xprint('Please enter a LETTER.')
            else:
                return guess
コード例 #13
0
ファイル: gallows.py プロジェクト: Chennaipy/hangman
    def _get_guess(self, already_guessed):
        """Gets the input from the user.

        Makes sure that the input entered is a letter and
        the letter entered is not already guessed by the user.
        """

        while True:
            xprint('Guess a letter.')
            guess = input().lower()
            if len(guess) != 1:
                xprint('Please enter a single letter.')
            elif guess in already_guessed:
                xprint('You have already guessed that letter. Choose again.')
            elif guess not in 'abcdefghijklmnopqrstuvwxyz':
                xprint('Please enter a LETTER.')
            else:
                return guess
コード例 #14
0
ファイル: ahorcado.py プロジェクト: ingtiti/ahorcado
    def _que_adivino(self, ya_seleccionada):
        """
        Toma la seleccion del usuario.
        Valida que la entrada sea solamente una letra y no un caracter especial
        Ademas valida que no se repida la seleccion
        """

        while True:
            xprint('Selecciona una letra.')
            guess = input().lower()
            if len(guess) != 1:
                xprint('Teclea solo una letra.')
            elif guess in ya_seleccionada:
                xprint('Esta letra ya la incluiste, seleciona otra distinta.')
            elif guess not in 'abcdefghijklmnopqrstuvwxyz':
                xprint('Solo escribe una LETRA.')
            else:
                return guess
コード例 #15
0
ファイル: ahorcado.py プロジェクト: ingtiti/ahorcado
    def _display_board(self):
        """Displiega el tablero de juego."""

        xprint(QUEMANDOSE[len(self._letra_error)])
        xprint()

        xprint('Letras fallidas:', end=' ')
        for letra in self._letra_error:
            xprint(letra, end=' ')
        xprint()

        #Convierte letras en espacios, segun palabra secreta
        blanks = '_' * len(self._palabra_secreta)

        # remplaza los espacios con la letra adivinada
        for i in range(len(self._palabra_secreta)):
            if self._palabra_secreta[i] in self._letra_correcta:
                blanks = blanks[:i] + self._palabra_secreta[i] + blanks[i+1:]

        # muestra la palabra secreta con espacios entre cada letra
        for letra in blanks:
            xprint(letra, end=' ')
        xprint()
コード例 #16
0
def play_again():
    """Returns True if the player wants to play again, False otherwise."""

    xprint('Do you want to play again? (yes or no)')
    return input().lower().startswith('y')
コード例 #17
0
    def _display_board(self):
        """Displays the current status of the game that is being played."""

        xprint(HANGMANPICS[len(self._missed_letters)])
        xprint()

        xprint('Missed letters:', end=' ')
        for letter in self._missed_letters:
            xprint(letter, end=' ')
        xprint()

        blanks = '_' * len(self._secret_word)

        # replace blanks with correctly guessed letters
        for i in range(len(self._secret_word)):
            if self._secret_word[i] in self._correct_letters:
                blanks = blanks[:i] + self._secret_word[i] + blanks[i + 1:]

        # show the secret word with spaces in between each letter
        for letter in blanks:
            xprint(letter, end=' ')
        xprint()
コード例 #18
0
ファイル: gallows.py プロジェクト: Chennaipy/hangman
def play_again():
    """Returns True if the player wants to play again, False otherwise."""

    xprint('Do you want to play again? (yes or no)')
    return input().lower() == 'yes'
コード例 #19
0
ファイル: gallows.py プロジェクト: Chennaipy/hangman
    def _display_board(self):
        """Displays the current status of the game that is being played."""

        xprint(HANGMANPICS[len(self._missed_letters)])
        xprint()

        xprint('Missed letters:', end=' ')
        for letter in self._missed_letters:
            xprint(letter, end=' ')
        xprint()

        blanks = '_' * len(self._secret_word)

        # replace blanks with correctly guessed letters
        for i in range(len(self._secret_word)):
            if self._secret_word[i] in self._correct_letters:
                blanks = blanks[:i] + self._secret_word[i] + blanks[i+1:]

        # show the secret word with spaces in between each letter
        for letter in blanks:
            xprint(letter, end=' ')
        xprint()