当前位置: 首页>>代码示例>>Python>>正文


Python Game.new_game方法代码示例

本文整理汇总了Python中models.Game.new_game方法的典型用法代码示例。如果您正苦于以下问题:Python Game.new_game方法的具体用法?Python Game.new_game怎么用?Python Game.new_game使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Game的用法示例。


在下文中一共展示了Game.new_game方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_game

# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import new_game [as 别名]
    def create_game(self, request):
        """ Create a new Game, Requires a unique username and email """
        user = self._get_user(request)

        games = Game.query(Game.user == user.key and Game.game_over == False).fetch()

        if len(games) == 0:
            Game.new_game(user.key)
            message = 'Game Created'
        else:
            message = 'You have already a running game'

        return StringMessage(message=message)
开发者ID:Ilyes-Hammadi,项目名称:hangman,代码行数:15,代码来源:api.py

示例2: new_game

# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import new_game [as 别名]
    def new_game(self, request):
        """Create new game for a user.

        Args:
            user_name (str): The username.
            num_card_types (int): The number of card types for the new game.

        Returns:
            game (Game): The representation of the Game instance.

        Raises:
            NotFoundException: If user_name is not found.
            BadRequestException: If num_card_types is not valid.
        """

        user = User.query(User.name == request.user_name).get()
        if not user:
            raise endpoints.NotFoundException(
                'A User with that name does not exist!')
        try:
            game = Game.new_game(user.key, request.num_card_types)
        except ValueError:
            raise endpoints.BadRequestException(
                'Number of card types must be between 2 and 13')

        return game.to_form(
            'Board size is %d cards ' % (game.num_card_types * 4) +
            '(0-%d). ' % (game.num_card_types * 4 - 1) +
            'Good luck playing Concentration!')
开发者ID:harber-d,项目名称:FSWD-P4-Design-A-Game,代码行数:31,代码来源:api.py

示例3: new_game

# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import new_game [as 别名]
    def new_game(self, request):
        """create new game"""
        # check if username exists
        user = User.query(User.username == request.username).get()
        if not user:
            raise endpoints.NotFoundException('No such user is registered!')

        # randomly generate answer and convert to nested list
        players = ['ronaldo', 'messi', 'bale', 'rooney', 'suarez', 'fabregas',
                   'cech', 'sanchez', 'aguero', 'hazard', 'benzema', 'neymar']
        answer = list(random.choice(players))
        answer = [[x, False] for x in answer] # boolean for whether letter guessed

        # store a game entity where user starts with 6 moves and 0 guesses
        history = []
        game = Game.new_game(user.key, answer, 6, 0, 'ongoing', history)

        # produce message
        message = 'A new game has been created for you %s' % request.username

        # produce hint
        hint = produce_hint(answer)

        # make form and return to user
        return game.to_form(message, hint, 'ongoing')
开发者ID:cardinal-tetra,项目名称:Soccer-Hangman,代码行数:27,代码来源:api.py

示例4: new_game

# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import new_game [as 别名]
 def new_game(self, request):
     """Creates new game"""
     user = User.query(User.name == request.user_name).get()
     if not user:
         raise endpoints.NotFoundException('User does not exist!')
     game = Game.new_game(user.key)
     return game.to_form('Time To Play HotStreak! You have 10 points.')
开发者ID:MistaVikz,项目名称:myGameAPI,代码行数:9,代码来源:api.py

示例5: new_game

# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import new_game [as 别名]
    def new_game(self, request):
        """Creates new rock, paper, scissors game and result.
        The player passes in their name and choice of rock,
        paper, or scissors, and the virtual player randomly
        selects a weapon.  The result (win,lose,draw)
        is determined."""
        user = User.query(User.name == request.user_name).get()
        if not user:
            raise endpoints.NotFoundException(
                'A User with that name does not exist!')
        try:
            game = Game.new_game(user.key, request.weapon)
        except ValueError:
            raise endpoints.BadRequestException('Maximum must be greater '
                                                'than minimum!')

        # Use a task queue to update the user wins.
        # This operation is not needed to complete the creation of a new game
        # so it is performed out of sequence.
        taskqueue.add(url='/tasks/cache_user_stats')

        if game.game_result == DRAW:
            msg = "it's a"
        elif game.game_result == UNKNOWN:
            msg = 'game state is'
        else:
            msg = 'you'
        return game.to_form('You selected {}, your '
                            'opponent selected {} -- '
                            '{} {}'.format(game.player_weapon,
                                           game.opponent_weapon,
                                           msg,
                                           game.game_result))
开发者ID:adarsh0806,项目名称:Udacity_P4_Game_App,代码行数:35,代码来源:api.py

示例6: new_game

# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import new_game [as 别名]
 def new_game(self, request):
     """Creates new game"""
     number_of_players = request.number_of_players
     user = User.query(User.name == request.user_name).get()
     opponent_key = None
     if not user:
         raise endpoints.NotFoundException(
             'A User with that user name does not exist!')
     if number_of_players != 2:
         raise endpoints.BadRequestException(
             'Number of players must be 2!')
     else:
         opponent = User.query(User.name == request.opponent_name).get()
         if not opponent:
             raise endpoints.NotFoundException(
                 'A User with that opponent name does not exists!')
         opponent_key = opponent.key
     rows = request.rows
     columns = request.columns
     try:
         game = Game.new_game(
             number_of_players,
             user.key,
             opponent_key,
             rows,
             columns)
     except ValueError:
         raise endpoints.BadRequestException('Dimensions must '
                                             'be greater than 0!')
     return game.to_form('New game is set, place your ships!')
开发者ID:seyfig,项目名称:BattleShip,代码行数:32,代码来源:api.py

示例7: new_game

# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import new_game [as 别名]
    def new_game(self, request):
        """Creates new game"""
        user = User.query(User.name == request.user_name).get()
        if not user:
            raise endpoints.NotFoundException(
                    'A User with that name %s does not exist!' % request.user_name)
        
        ### user b is another user online
        opponent = User.query(User.name == request.opponent_name).get()
        if not opponent:
            raise endpoints.NotFoundException(
                    'A User with that name %s does not exist!' % request.opponent_name)

        try:
            ### user is the one for the first move in the new game
            game = Game.new_game(user=user.key, user_tic=request.user_tic, 
              opponent=opponent.key, opponent_tic=request.opponent_tic, 
              user_of_next_move=user.key)
        except ValueError:
            raise endpoints.BadRequestException('Value Error')

        # Use a task queue to cache winning chance
        taskqueue.add(url='/tasks/cache_winning_chance/')

        taskqueue.add(url='/tasks/cache_winning_chance/', target="worker", 
            params={'user_name':request.user_name}, name="cache-winning-chance")

        GLOBAL_CURRENT_USER_NAME = request.user_name
        
        return game.to_form('Good luck playing Tic-Tac-Toe!')
开发者ID:kensupernova,项目名称:tic-tac-toe-game-api,代码行数:32,代码来源:api.py

示例8: new_game

# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import new_game [as 别名]
    def new_game(self, request):
        """Creates new game"""
        user1 = User.query(User.name == request.player1_name).get()
        if not user1:
            raise endpoints.NotFoundException(
                'User 1 does not exist!')
        user2 = User.query(User.name == request.player2_name).get()
        if not user2:
            user2key = user2
        else:
            user2key = user2.key

        player1_primary_grid = GameLogic.place_ship_on_grid(
                                request,
                                '1')
        player2_primary_grid = GameLogic.place_ship_on_grid(
                                request,
                                '2')
        player1_tracking_grid = GameLogic.create_default_grid()
        player2_tracking_grid = GameLogic.create_default_grid()

        game = Game.new_game(user1.key, user2key,
                             player1_primary_grid,
                             player2_primary_grid,
                             player1_tracking_grid,
                             player2_tracking_grid)

        return game.to_form('Good luck playing Battleship!')
开发者ID:daroldso,项目名称:battleship-game-api,代码行数:30,代码来源:api.py

示例9: new_game

# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import new_game [as 别名]
    def new_game(self, request):
        """Creates a Game.
            Args:
            request: The NEW_GAME_REQUEST objects, which includes two players'
                names
            Returns:
                GameForm with created game
            Raises:
                endpoints.NotFoundException: If the user does not exist.
                endpoints.BadRequestException: If the game is created with one
                user.
        """
        user_x = User.query(User.name == request.user_name_x).get()
        user_o = User.query(User.name == request.user_name_o).get()
        if (not user_o) or (not user_x):
            raise endpoints.NotFoundException(
                    'A User with that name does not exist!')
        try:
            game = Game.new_game(user_x.key, user_o.key)
            history = History(game=game.key)
            history.put()
        except ValueError:
            raise endpoints.BadRequestException('Players should be '
                                                'different!')

        return game.to_form('Good luck playing TicTacToe!')
开发者ID:NadiiaLukianenko,项目名称:tictactoegame,代码行数:28,代码来源:api.py

示例10: new_game

# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import new_game [as 别名]
    def new_game(self, request):
        """Creates new game"""
        north_user = self.get_user_or_error(request.north_user_name)
        south_user = self.get_user_or_error(request.south_user_name)
        game = Game.new_game(north_user.key, south_user.key)

        return game.to_form('Good luck playing Kalah!')
开发者ID:samfrances,项目名称:udacity-kalah,代码行数:9,代码来源:api.py

示例11: new_game

# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import new_game [as 别名]
 def new_game(self, request):
     """ Creates a new game """
     user = User.query(User.name == request.user).get()
     if not user:
         raise endpoints.NotFoundException("This user doesn't exist")
     game = Game.new_game(user=user.key)
     return game.to_message()
开发者ID:diogovk,项目名称:peg-solitarie-backend-udacity,代码行数:9,代码来源:api.py

示例12: new_game

# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import new_game [as 别名]
 def new_game(self, request):
     """Creates new BlackJack game. For a new user, he has 100 initial dollars."""
     user = User.query(User.name == request.user_name).get()
     if not user:
         raise endpoints.NotFoundException('User does not exist!')
     game = Game.new_game(user.key)
     return game.to_form('Time To Play BlackJack! You have %d dollars' %(user.total_dollars))
开发者ID:VinceWang92,项目名称:GameApi-BlackJack,代码行数:9,代码来源:api.py

示例13: create_new_game

# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import new_game [as 别名]
    def create_new_game(self, request):
        """Create a new tictactoe game between 2 players

        Args: 
          NEW_GAME_REQUEST: Details of new game in GameForm format

        Returns:
          New game in GameForm format along with Confirmation message

        Raises:
          NotFoundException: if either user specified in input GameForm
          is not found in user model

        """
        userX = User.query(User.name == request.userX)
        userO = User.query(User.name == request.userO)
        if not userX:
            raise endpoints.NotFoundException(
                'User {} does not exist'.format(request.userX))
        if not userO:
            raise endpoints.NotFoundException(
                'User {} does not exist'.format(request.userO))

        game = Game.new_game(userX.key, userO.key)
        game.put()

        return game.to_form('Game created. {} to play first'.format(
                                                    request.userX))
开发者ID:gauravanand1212,项目名称:design_a_game,代码行数:30,代码来源:api.py

示例14: new_game

# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import new_game [as 别名]
 def new_game(self, request):
     """Creates a new game"""
     user = User.query(User.name == request.user_name).get()
     if not user:
         raise endpoints.NotFoundException(
             'A User with that name does not exist!')
     game = Game.new_game(user.key, datetime.datetime.now())
     return game.to_form('Good luck!')
开发者ID:archzzz,项目名称:Udacity-Full-Stack-Nanodegree-Projects,代码行数:10,代码来源:concentration.py

示例15: new_game

# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import new_game [as 别名]
 def new_game(self, request):
     """Creates new game."""
     user = User.query(User.username == request.username).get()
     if not user:
         raise endpoints.NotFoundException(
             'A User with that name does not exist!')
     game = Game.new_game(user.key)
     return game.to_form('Good luck playing Rock, Paper, Scissors!')
开发者ID:hessler,项目名称:udacity-fsnd-p4-design-a-game,代码行数:10,代码来源:api.py


注:本文中的models.Game.new_game方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。