示例#1
0
 def cancel_game(self, request):
     """
     Cancels a Blackjack Marathon game based on key.
     """
     profile_key = Profile.get_profile_from_user().key
     Game.cancel_game(profile_key, request.urlsafe_game_key)
     return StringMessage(message='Game cancelled successfully.')
示例#2
0
 def new_game(self, request):
     """
     Creates a new Blackjack Marathon game for a user.
     """
     profile = Profile.get_profile_from_user()
     game = Game.new_game(p_key=profile.key)
     game.put()
     return game.to_form('Good luck playing Blackjack Marathon!')
示例#3
0
    def get_user_games(self, request):
        """Return the user's active games."""
        profile = Profile.get_profile_from_user()

        # Create ancestor query for all key matches for this user.
        # Filter on games where points_remaining > 0
        games = Game.query(ancestor=profile.key). \
            filter(Game.points_remaining > 0)
        # return set of GameForm objects per game
        return GameForms(
            items=[game.to_form() for game in games]
        )
示例#4
0
 def make_move(self, request):
     """
     Makes a move on a given Blackjack Marathon game. The move is the user's
     chosen strategy based on the current player and Dealer card hands.
     """
     # Verify the strategy passed in
     if request.strategy not in STRATEGIES:
         raise endpoints.BadRequestException('Invalid strategy {} '
                                             'passed in'.format(
                                                 request.strategy))
     return Game.apply_strategy(Profile.get_profile_from_user().key,
                                request.urlsafe_game_key,
                                request.strategy)
示例#5
0
 def get_profile(self, request):
     """Return user profile."""
     profile = Profile.get_profile_from_user()
     return profile.to_form()