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


Python Game.get_from_key方法代码示例

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


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

示例1: get_game

# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import get_from_key [as 别名]
 def get_game(self, request):
     """ Returns the current state of a certain game """
     game = Game.get_from_key(urlsafe_key=request.game_key)
     if game:
         return game.to_message()
     else:
         raise endpoints.NotFoundException("The game could not be found")
开发者ID:diogovk,项目名称:peg-solitarie-backend-udacity,代码行数:9,代码来源:api.py

示例2: cancel_game

# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import get_from_key [as 别名]
 def cancel_game(self, request):
     """ Delete a non-ended game """
     game = Game.get_from_key(urlsafe_key=request.game_key)
     if not game:
         raise endpoints.NotFoundException("The game could not be found")
     if game.game_over:
         raise endpoints.BadRequestException("The game is already over!")
     else:
         game.key.delete()
         return StringMessage(message="Game successfully canceled.")
开发者ID:diogovk,项目名称:peg-solitarie-backend-udacity,代码行数:12,代码来源:api.py

示例3: get_game_history

# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import get_from_key [as 别名]
 def get_game_history(self, request):
     """
     Gets the movement history for a specific game.
     Each moviement is composed of two fields separated by colon.
     The first is the origin point in the board.
     The second is the direction which can be 'u', 'd', 'l', 'r'
     for 'up', 'down', 'left' and 'right' respectively.
     """
     game = Game.get_from_key(urlsafe_key=request.game_key)
     if not game:
         raise endpoints.NotFoundException("The game could not be found")
     return game.to_historymessage()
开发者ID:diogovk,项目名称:peg-solitarie-backend-udacity,代码行数:14,代码来源:api.py

示例4: give_up

# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import get_from_key [as 别名]
 def give_up(self, request):
     """
     Gives up a game. The game will be ended and scores will be calculated.
     """
     game = Game.get_from_key(urlsafe_key=request.game_key)
     if not game:
         raise endpoints.NotFoundException("The game could not be found")
     if game.game_over:
         raise endpoints.BadRequestException("The game is already over")
     gamelogic.end_game(game)
     self.commit_game_end(game)
     return StringMessage(message="Game ended. Score: %s." % game.score)
开发者ID:diogovk,项目名称:peg-solitarie-backend-udacity,代码行数:14,代码来源:api.py

示例5: make_move

# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import get_from_key [as 别名]
 def make_move(self, request):
     """ Make move in the game, returning the new game state"""
     game = Game.get_from_key(urlsafe_key=request.game_key)
     if not game:
         raise endpoints.NotFoundException("The game could not be found")
     try:
         game = gamelogic.make_move(
                 game, (request.origin_point, request.direction))
     except (ValueError, gamelogic.InvalidMoveExpection) as e:
         raise endpoints.BadRequestException(e.message)
     if game.game_over:
         gamelogic.end_game(game)
         self.commit_game_end(game)
     else:
         game.put()
     return game.to_message()
开发者ID:diogovk,项目名称:peg-solitarie-backend-udacity,代码行数:18,代码来源:api.py


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