示例#1
0
 def __init__(self, phrase):
     self.original_phrase = phrase
     self.phrase_chars = []
     for char in phrase.strip():
         char = Character(char)
         char.update_in_phrase(phrase)
         self.phrase_chars.append(char)
示例#2
0
 def goal_guess(self):
     """ Returns the maximum number of characters that can be guessed in the phrase """
     goal = 0
     for char in self.phrase:
         if Character.get_char(char) != " ":
             goal += 1
     return goal
示例#3
0
 def __init__(self, phrase):
     '''
     Parameters
     ----------
     phrase : str
         The string containing characters to be instantiated as Character objects
     '''
     self.phrase = [Character(c) for c in phrase]
示例#4
0
    def __init__(self, phrase):
        self.phrase = phrase

        for char in self.phrase:
            self.append(Character(char))

        for char in self:
            if char.original == " ":
                char.was_guessed = True
示例#5
0
 def __init__(self, phrase):
     """
     Takes an incoming phrase and stores it into the phrase attribute.
     Creates the letters attribute as an empty list and loops over the characters self.phrase
     and calls the Character Object with each letter as the argument.
     """
     self.phrase = phrase
     self.letters = []
     for letter in self.phrase:
         self.letters.append(Character(letter))
示例#6
0
 def __init__(self, phrase):
     """Constructor to setup the phrase and split it to characters
     
     Parameters
     ----------
     phrase : str
         The selected phrase to be guessed
     """
     self.phrase = phrase
     self.phrase = [Character(char) for char in self.phrase]
示例#7
0
 def __init__(self, phrase):
     """
     Constructor for the character class
     
     Parameters
     ----------
     phrase : str
         This is called by the phrasehunter.game.Game object's constructor.
     """
     self._was_guessed = False
     self.phrase = [Character(char) for char in phrase]
示例#8
0
 def __init__(self, phrase):
     '''
     :param phrase:
     :type phrase:
             Attributes:
         phrasestr (str): the phrase, in string format
         phrase (list of Character): the phrase as a list of Characters
         author (str): the author of the quote
     '''
     self.phrasestr = self.format_phrase(phrase[0])
     self.phrase = [Character(char) for char in self.phrasestr]
     self.author = phrase[1]
示例#9
0
def create_phrases() -> List[Phrase]:
    """Creates a list of phrases"""
    phrases: List[Phrase] = []
    str_phrases = ['Hello', 'Cowboy', 'Christmas', 'Santa Claus', 'Univers']

    for phrase in str_phrases:
        try:
            chars = [Character(char) for char in phrase]
        except ValueError as err:
            print(f'\nError: {err}\n')
        else:
            phrases.append(Phrase(chars))

    return phrases
示例#10
0
 def take_guess(self):
     """Takes a guess input and return it as a Character object if it has not already been guessed"""
     while True:
         try:
             guess = Character(input('Take a guess >>> ').lower())
             if not guess.char.isalpha() or len(guess.char) != 1:
                 print('Guess must be a letter in the alphabet.')
                 continue
             if guess.char in [char.char for char in self.guessed]:
                 print('You already guessed that!')
                 del (guess)
             else:
                 self.guessed.append(guess)
                 return guess
         except ValueError:
             print('Guess must be a single letter.')
示例#11
0
    def __init__(self, phrase):

        from phrasehunter.character import Character

        # Players will only be allowed to guess a letter.
        self.valid_guesses = [
            'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
            'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
        ]
        self.length = int(len(phrase))
        self.incorrect_count = int(0)
        self.collection = []
        self.collection_names = []
        self.all_guesses = []

        # The Phrase instance will consist of a list of Character instances.
        for char in phrase:
            self.collection_names.append(str(char).lower())
            char = Character(char)
            self.collection.append(char)

        # Since spaces are counted as an automatic guess, these should be included
        # in the correct_count attribute.
        self.correct_count = (int(0)) + self.collection_names.count(" ")
示例#12
0
 def __init__(self, phrase, words_left=0):
     self.phrase = [Character(char) for char in phrase]
     self.words_left = words_left
     print(self.phrase)
示例#13
0
 def __init__(self, phrase):
     letters = list(phrase)
     self.characters = [Character(letter) for letter in letters]
示例#14
0
 def reset_phrase(self):
     """
     Resets the guess status for all the characters in the phrase back to False
     """
     for char in self.phrase:
         Character.reset_guessed(char)
示例#15
0
 def __init__(self, phrase):
     """ Initializes a Phrase object """
     self.phrase = []  # a collection of Character objects
     for char in phrase:
         self.phrase.append(Character(char))
     self.all_char_guessed = False
示例#16
0
# Import your Game class
from phrasehunter.game import Game
from phrasehunter.phrase import Phrase
from phrasehunter.character import Character

# Create your Dunder Main statement.

# Inside Dunder Main:
# Create an instance of your Game class
# Start your game by calling the instance method that starts the game loop
if __name__ == '__main__':
    new_game = Game("test game")
    Game.test_class()
    Phrase.test_class()
    Character.test_class()
    new_game.run_game()

示例#17
0
 def __init__(self, phrases):
     super().__init__(phrases)
     self.phrase = []
     self.guessed = False
     for char in phrases:
         self.phrase.append(Character(char))
示例#18
0
 def __init__(self, phrase):
     super().__init__()
     if os.environ.get('DEBUG', False):
         self._phrase = phrase
     for char in phrase:
         self.append(Character(char))
示例#19
0
 def __init__(self, phrase):
     self.phrase = phrase  #a list of string of the phrases
     self.characters_in_phrase = [Character(char) for char in phrase]
示例#20
0
 def __init__(self, phrase):
     self.phrase = phrase
     self.list_of_char = [Character(letter) for letter in phrase]