本文整理汇总了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")
示例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.")
示例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()
示例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)
示例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()