def create_phrases(self): """Creates a list of Phrase objects""" return [ Phrase("My precious"), Phrase("All righty then"), Phrase("Show me the money"), Phrase("I see dead people"), Phrase("That escalated quickly") ]
def __init__(self): self.missed = 0 self.phrases = [Phrase('A New Hope'), Phrase('The Empire Strikes Back'), Phrase('Return of the Jedi'), Phrase('The Force Awakens'), Phrase('The Last Jedi')] self.active_phrase = None #guesses contains space to simply win checking self.guesses = [' ']
def __init__(self): self.missed = 0 self.phrases = [Phrase("you cant handle the truth"), Phrase("why so serious"), Phrase("just keep swimming"), Phrase("i see dead people"), Phrase("there is no crying in baseball") ] self.active_phrase = self.get_random_phrase() self.guesses = [" "]
def create_phrase(self): #A method which creates 5 marvel phrases. marvel_phrases = [ Phrase("Wakanda Forever"), Phrase("I am Ironman"), Phrase("We are Groot"), Phrase("We have a Hulk"), Phrase("I could do this all day") ] return marvel_phrases
def __init__(self, **kwargs): self.phrases = [ Phrase("You had me at hello"), Phrase("You got a friend in me"), Phrase("May the force be with you"), Phrase("Just keep swimming"), Phrase("This is a tasty burger") ] for key, value in kwargs.items(): setattr(self, key, value)
def __init__(self): self.missed = 0 self.phrases = [ Phrase('In God we Trust'), Phrase('The sky is blue'), Phrase('I want to learn to code'), Phrase('Did I do a good job'), Phrase('I want to live forever') ] self.active_phrase = None self.guesses = []
def __init__(self): self.missed = 0 self.phrases = [ Phrase("fly you fools"), Phrase("you shall not pass"), Phrase("a wizard is never late"), Phrase("for rohan"), Phrase("i am no man") ] self.active_phrase = random.choice(self.phrases) self.guesses = []
def get_random_phrase(self): """Chooses a random phrase from the list""" phrases = [ Phrase('The best of both worlds'), Phrase('Speak of the devil'), Phrase('Once in a blue moon'), Phrase('When pigs fly'), Phrase('Kill two birds with one stone') ] phrase_object = random.choice(phrases) return phrase_object
def __init__(self): self.missed = 0 self.phrases = [ Phrase("Hello world"), Phrase("How are you"), Phrase("Thank you"), Phrase("No problem"), Phrase("Good luck") ] self.active_phrase = self.get_random_phrase() self.guesses = [" "]
def __init__(self): self.lives = 5 self.phrases = [ Phrase("Truth always reveals itself"), Phrase("Learning to code is challenging"), Phrase("My brain is melting"), Phrase("I should have been a computer science major"), Phrase("You live and you learn") ] self.active_phrase = random.choice(self.phrases) self.guesses = [" "]
def __init__(self): self.missed = 0 self.guesses = [" "] self.phrases = self.phrases = [ Phrase("Vancouver Canucks"), Phrase("Calgary Flames"), Phrase("Winnipeg Jets"), Phrase("Toronto Maple Leafs"), Phrase("Montreal Canadians") ] self.active_phrase = None
def __init__(self): self.missed = 0 # -- https://randomwordgenerator.com/ -- self.phrases = [ Phrase("hello world"), Phrase("Amazing pie"), Phrase("Black cat"), Phrase("Sparkling water"), Phrase("large chair") ] self.active_phrase = None self.guesses = []
def __init__(self): self.missed = 0 self.clue_received = 0 self.phrases = [ Phrase('Hello world'), Phrase('Just keep swimming'), Phrase('Get to the chopper'), Phrase('There is no place like home'), Phrase('May the force be with you') ] self.active_phrases = self.get_random_phrase() self.guesses = [" "]
def __init__(self): self.missed = 0 self.phrases = [ Phrase("Life is like a box of chocolates"), Phrase("Tomorrow is another day"), Phrase("May the Force be with you"), Phrase("Go away or I shall taunt you a second time"), Phrase("Sometimes you eat the bear sometimes the bear eats you"), ] self.active_phrase = random.choice(self.phrases) self.guesses = [" "]
def __init__(self): """ Pull and store a random phrase from the list of phrases stored in the class variable. The phrase is entered into a Phrase Object and stored into the random_phrase attributes. Loop through each letter in the selected phrase and store it in the class variable active_phrase. """ self.phrase = random.choice(self.phrase_bank) self.random_phrase = Phrase(self.phrase) for letter in self.phrase: if not letter.isspace(): self.active_phrase.append(letter.lower())
def __init__(self): self.missed = 0 self.allowed_misses = 5 self.phrases = [ Phrase('The Remains of the Day'), Phrase('A Pale View of Hills'), Phrase('An Artist of the Floating World'), Phrase('Never Let Me Go'), Phrase('The Buried Giant') ] self.allowed_chars = list('abcdefghijklmnopqrstuvwxyz') self.active_phrase = None self.guesses = []
def __init__(self, phrases): ''' :param phrases: list of phrases which can be used for the game :type phrases: list of tuples (each tuple contains phrase and author) Attributes: phrase = one quote (selected randomly from the list of quotes passed in) won = flag to indicate whether game won or not, True or False lives = count of number of lives a player has left. Starts at 5, reduces by 1 for each incorrect guess letters_guessed = a list which keeps track of which letters the player has guessed ''' self.phrase = Phrase(phrases[random.randint(0, len(phrases) - 1)]) self.won = False self.lives = 5 self.letters_guessed = []
def start(self): self.welcome() while self.missed < 5 and self.active_phrase.check_complete( self.guesses) == False: print(f"\nNumber missed: {self.missed}\n") Phrase.display(self.active_phrase, self.guesses) self.user_guess = self.get_guess() self.guesses.append(self.user_guess) self.active_phrase.check_guess(self.user_guess) if self.active_phrase.check_guess(self.user_guess): print("\nCorrect!") else: self.missed += 1 print("\nNope, try again!") self.game_over()
def reset(self): """ Resets all previous game data if player decides to play again. """ self.active_phrase.clear() self.correct_answers.clear() self.player_answers.clear() self.lives = 5 self.game_over = False self.play_game = True self.phrase = random.choice(self.phrase_bank) self.random_phrase = Phrase(self.phrase) for letter in self.phrase: if not letter.isspace(): self.active_phrase.append(letter.lower())
def __init__(self): self.Guess = '' self.guesses = [] self.missed = 0 self.active_phrase = None #Credits for the beautiful list comprehension below go to: Jennifer Nordell self.phrases = [Phrase(phrase_string) for phrase_string in string_list]
def __init__(self, phrases, attempts=5): self.original_phrases = phrases self.phrases = [Phrase(phrase) for phrase in phrases] self.active_phrase = random.choice(self.phrases) self.guessed = [] self.guesses = 0 self.attempts = attempts
def __init__(self): import re, random from phrasehunter.phrase import Phrase with open("phrasehunter/phrase_master_list.txt") as open_file: data = open_file.read() # Ensure there is at least one valid phrase in phrase_master_list.txt. try: random_phrase = random.choice(re.findall(r'[\w ]+[^\n\d_]', data)) self.current_phrase = Phrase(random_phrase) except IndexError as err: print( "There are currently no saved phrases. Please add at least one valid" " phrase before playing the game.")
def __init__(self): self.missed = 0 self.show_name = random.choice(list(phrase_bank_tv.keys())) self.phrases = [ Phrase(item) for item in phrase_bank_tv[self.show_name] ] self.active_phrase = random.choice(self.phrases) self.guesses = [" "]
def __init__(self): """ missed: number of wrong guesses phrases: pool of phrases to randomly choose from active_phrase: the phrase currently being guessed guesses: all the guesses by the player """ self.missed = 0 # Corrected typo, changed the elements to Phrase objects self.phrases = [ Phrase("Once in a blue moon"), Phrase("When pigs fly"), Phrase("A piece of cake"), Phrase("Break a leg"), Phrase("Jupyter notebook") ] self.active_phrase = None self.guesses = []
def __init__(self): # Tracks the number of missed guesses by the player self.missed = 0 # list of phrase objects to use with the game self.phrases = [ Phrase('Come at me bro'), Phrase('as easy as pie'), Phrase('Epic Sax Guy'), Phrase('Hello world'), Phrase('One of a kind') ] # Phrase object that is currently in play self.active_phrase = self.get_random_phrase() # list that contains all the guesses made by the user during the course of the game self.guesses = [' ']
class Game(): def __init__(self): import re, random from phrasehunter.phrase import Phrase with open("phrasehunter/phrase_master_list.txt") as open_file: data = open_file.read() # Ensure there is at least one valid phrase in phrase_master_list.txt. try: random_phrase = random.choice(re.findall(r'[\w ]+[^\n\d_]', data)) self.current_phrase = Phrase(random_phrase) except IndexError as err: print( "There are currently no saved phrases. Please add at least one valid" " phrase before playing the game.") def start_game(self, *args): print('Welcome to the Guess-That-Phrase! Guess the phrase to win!') # Display the initial phrase with hidden characters. for char in self.current_phrase.collection: print(char.show(), end=" ") print("\n") while self.current_phrase.correct_count < self.current_phrase.length and self.current_phrase.incorrect_count < int( 5): # Collect user guesses. self.current_phrase.check_guess( input('What letter would you like to guess? ')) # If there are five incorrect guesses, the player loses. if self.current_phrase.incorrect_count == 5: print('Sorry, you lose. Only five incorrect guesses are allowed.') # If the player guesses all characters in the phrase, they win. elif self.current_phrase.correct_count == self.current_phrase.length: print('Congratulations! You guessed the phrase. You win.') print("Would you like to play again?")
def __init__(self, phrases): """Constructor for taking in the phrase and processing it into characters Parameters ---------- phrases : string Phrase that the user will have to guess. """ self.guesses = [] self.phrases = [Phrase(phrase) for phrase in phrases.copy()] self.selected_phrase = choice(self.phrases) self.lives = 5
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
def __init__(self, phrases): """ Constructor for the phrasehunter.game.Game class. Parameters ---------- phrases : list This is can be edited in phrasehunter.phrases, which contains one list object, quote_list. """ self.phrases = [Phrase(phrase) for phrase in phrases] self.guesses = [] self.current_phrase = self.phrases[0] self.phrase_counter = 0 self.life_counter = 0 self.life_limit = 3 self.wants_to_play = True
from phrasehunter.game import Game from phrasehunter.phrase import Phrase if __name__ == "__main__": game = Game() game.start() phrase = Phrase(game.phrases)