def start(): root.destroy() log(level, "Was the level selected") window = Tk() game = Hangman(window, level) game.play() window.mainloop()
def post(self): """Create a new game.""" # Return 201 w/ location header and game data object. identifier = get_identifier() game = Hangman(random.choice(Hangman.PHRASES)) games[identifier] = game game_json = get_game_obj(game, id=identifier) headers = {'Location': api.url_for(GameAPI, identifier=identifier)} return game_json, 201, headers
def start_game(): number_of_allowed_playing = 5 han = Hangman() #if the number of turn less than 5, play and update all the property while han.turn_count < number_of_allowed_playing: letter = han.play() #set the bad guess han.bad_guessed_letters = letter # set the well guess han.well_guessed_letters = letter #compute if there is an error han.error_count = letter #compute the number of good answers han.good_answers = letter #after playing, a turn print the following print("good answers=", han.good_answers) print("bad_guessed_letters_list", han.bad_guessed_letters) print("well_guessed_letters list=", han.well_guessed_letters) print("error_count=", han.error_count) print("number of available playing", han.life) print("number of turn playing", han.turn_count) return
def main(): h = Hangman() h.play_game()
from game import Hangman from helpers import load_words words = load_words("hangman/slowa.txt") game = Hangman(words) game.play()
from game import Hangman game1=Hangman() game1.start_game()
def main(): # Objeto game = Hangman(rand_word()) # Enquanto o jogo não tiver terminado, print do status, solicita uma letra e faz a leitura do caracter check = False while check is False: game.print_game_status() letter = input('\n\nInforme uma letra: ').lower() game.guess(letter) game.hide_word() check = game.hangman_over() # Verifica o status do jogo game.print_game_status() # De acordo com o status, imprime mensagem na tela para o usuário if game.hangman_won(): print('\nParabéns! Você venceu!!') print('A palavra era ' + game.word) else: print('\nGame over! Você perdeu.') print('A palavra era ' + game.word) print('\nFoi bom jogar com você! Agora vá estudar!\n')
from game import Hangman hangman = Hangman() hangman.start_game()
from game import Hangman Hangman().play()
def website(): invalid_guess = False if request.method == 'GET': # Several scenarios: # * Attempt to load an existing game if session data exists. # * If session data doesn't correspond to an existing game then # remove the data and present the splash screen. # # * Show the splash screen if session data does not exist. try: identifier = session['hangman'] game = games[identifier] except KeyError: # Either session data does not exist # or a game does not exist for the session data. session.pop('hangman', None) return render_template( 'index.html', data={'leaderboard': get_leaderboard_data()}) elif request.method == 'POST': # Several scenarios: # * Post from forms: # * 'play' game from splash screen. # * 'guess' during game (possibly pass back validation error). # * 'high-score' after game has been won. # * 'exit' during or after game has finished. # Get the current game (or create one). # Implicitly handles post action for 'play' game form. try: identifier = session['hangman'] game = games[identifier] except KeyError: # Clean and recreate session/game. identifier = get_identifier() game = Hangman(random.choice(Hangman.PHRASES)) games[identifier] = game session['hangman'] = identifier # Handle POST action. if 'guess' in request.form: input_guess = request.form['guess-text'] if game.is_guess_valid(input_guess): game.guess(input_guess) else: invalid_guess = True elif 'high-score' in request.form or 'exit' in request.form: # The game is over, remove the game and session. if 'high-score' in request.form: # Note: High score is # of tries used, so lower is better. # Ensure the user name length is valid. user = request.form['user'][:UserScore.USER_NAME_MAX_LENGTH] score = game.get_tries() db.session.add(UserScore(user=user, score=score)) db.session.commit() del games[identifier] del session['hangman'] return render_template( 'index.html', data={'leaderboard': get_leaderboard_data()}) return render_template('index.html', data={ 'leaderboard': get_leaderboard_data(), 'game': get_game_obj(game, invalid_guess=invalid_guess) })