def create_game(user_name, misses_allowed):
    """Create a game"""
    user = User.get_by_name(user_name)
    secret_word = secret_word_generator()
    current_solution = ''.join(['_' for l in secret_word])

    # Check if misses_allowed exists and if so make sure it's a number
    if misses_allowed:
        if not misses_allowed.isnumeric():
            msg = 'Error, only numbers are allowed in misses_allowed'
            raise endpoints.BadRequestException(msg)
        else:
            misses_allowed = int(misses_allowed)

    else:
        misses_allowed = 5

    game = Game.create_game(user=user.key,
                            misses_allowed=misses_allowed,
                            secret_word=secret_word,
                            current_solution=current_solution)

    return game.game_state('A new game of Hangman has been created!')
def get_user_scores(user_name):
    """Get a user's scores"""
    user = User.get_by_name(user_name)
    scores = Score.query(Score.user == user.key)
    return ScoreForms(items=[score.create_form() for score in scores])
def get_user(user_name):
    """Get a user"""
    user = User.get_by_name(user_name)
    return user
def get_user_games(user_name):
    """Get a user's games"""
    user = User.get_by_name(user_name)
    games = Game.query(ancestor=user.key)
    games = games.filter(Game.game_cancelled == False, Game.game_over == False)
    return GameStateForms(items=[game.game_state() for game in games])