本文整理匯總了Python中models.History.turn方法的典型用法代碼示例。如果您正苦於以下問題:Python History.turn方法的具體用法?Python History.turn怎麽用?Python History.turn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models.History
的用法示例。
在下文中一共展示了History.turn方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _make_move
# 需要導入模塊: from models import History [as 別名]
# 或者: from models.History import turn [as 別名]
def _make_move(self, game, user, at_position, p):
try:
history = History(parent=game.key)
history.user = user.key
history.guess = p.coordinate
history.turn = game.turn
if game.player1_turn:
history.player_turn = 1
else:
history.player_turn = 2
if at_position <= 0:
message = 'Miss!'
history.result = 'miss'
history.put()
game.set_fired(user, p.d)
game.put()
else:
message = "Hit!"
history.result = 'hit'
ships_query = Ship.query(ancestor=game.key)
filter_query = ndb.query.FilterNode('user', '=', user.key)
ships_query1 = ships_query.filter(filter_query)
filter_query = ndb.query.FilterNode('type', '=', at_position)
ships_query2 = ships_query1.filter(filter_query)
ship = ships_query2.get()
if not ship:
filter_query = ndb.query.FilterNode(
'type', '=', str(at_position))
ships_query3 = ships_query1.filter(filter_query)
ship = ships_query3.get()
ship.hits += 1
game.set_fired(user, p.d)
if(ship.is_sank()):
message += " Ship %s sank" % ShipType(at_position)
game.sink_ship(user, at_position)
history.put()
ship.put()
game.put()
except ValueError as e:
raise endpoints.BadRequestException(e)
return game.to_form(message)