本文整理汇总了Python中models.Game.get方法的典型用法代码示例。如果您正苦于以下问题:Python Game.get方法的具体用法?Python Game.get怎么用?Python Game.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Game
的用法示例。
在下文中一共展示了Game.get方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import get [as 别名]
def get(self):
game = Game.get(self.request.get('game'))
if not game:
self.error(403)
return
user = users.GetCurrentUser()
# User needs to join game
if user not in game.players:
self.redirect('/joingame?game=' + str(game.key()))
list_of_live_stagegameplayers = []
list_of_dead_stagegameplayers = []
for player in game.players:
if player.isAlive:
list_of_live_stagegameplayers.append(player)
else:
list_of_dead_stagegameplayers.append(player)
self.generate('play.html', {
'current_stage': game.currentStage,
'list_of_live_stagegameplayers': list_of_live_stagegameplayers,
'list_of_dead_stagegameplayers': list_of_dead_stagegameplayers,
'list_of_votes': game.currentStage.votes,
})
示例2: post
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import get [as 别名]
def post(self):
game = Game.get(self.request.get('game'))
if not game:
self.error(403) # game does not exist
return
if not game.current_user_moderating():
self.error(403)
return
#need the currentStage for index and day/night swap
if game.currentStage:
current_stage = game.currentStage
new_stage = Stage(index = current_stage.index + 1, game = game)
new_stage.isDay = not current_stage.isDay
for player in current_stage.StageGamePlayer_set:
#copy values from previous StageGamePlayer relationships
new_player = StageGamePlayer(stage = new_stage,
player = player.player,
isAlive = player.isAlive)
new_player.put()
else:
new_stage = Stage(index = 0, game = game, isDay = True)
for player in game.GamePlayer_set:
#create values from players in game
new_player = StageGamePlayer(stage = new_stage,
player = player,
isALive = True)
new_player.put()
new_stage.put()
self.redirect('/managestage?stage=' + str(new_stage.key()))
示例3: accept_or_decline_game
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import get [as 别名]
def accept_or_decline_game(id, action, user, content):
"""Join/invite/decline actions for games."""
game = Game.get(id)
player = Player.get(user, game)
started = False
if action == 'add':
player.set_status_joined()
joined = [p for p in game.players
if p.status == Player.JOINED]
if len(joined) == game.max_players:
notify(
[p.user.device for p in game.players if p.user.device and p != player],
'Politically Incorrect',
'The game "{}" has started!'.format(game.name)
)
game.start()
started = True
elif action == 'delete':
player.set_status_denied()
else:
return jsonify(), 404
try:
db.session.commit()
except:
db.session.rollback()
raise
return jsonify(started=started)
示例4: invite
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import get [as 别名]
def invite(id, user, content):
"""Invites a list of users."""
game = Game.get(id)
if not (user == game.host and game.status == Game.PENDING):
return jsonify(message='I can\'t let you do that, Dave.'), 418
emails = content['emails']
users = User.get_all(emails)
players = Player.create_all(users, game)
game.invite_all(players)
try:
db.session.commit()
except:
db.session.rollback()
raise
return jsonify()
示例5: play
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import get [as 别名]
def play(id, user, content):
"""
Handle main gameplay. If the requesting user
is the current judge, then expect an email
in the request body and interpret it as
the round winner chosen by the judge. Otherwise,
the request body should contain card ids in the
user's hand, which should be placed on the table.
request :=
POST ({
'cards': [int]
} | {
'email': str
})
"""
game = Game.get(id)
player = Player.get(user, game)
if game.status != Game.ONGOING:
return jsonify(message='This game isn\'t in-progress.'), 418
if user == game.judge.user:
email = content['email']
winner = next(
(player for player in game.players if player.user.email == email),
None
)
winner.add_points(1)
game.new_round(winner)
else:
if player.played:
return jsonify(), 418
cards = content['cards']
map = {card.id: card for card in player.hand}
cards = [map[card] for card in cards]
if len(cards) != game.black_card.answers:
return jsonify(message='Invalid play, mate.'), 418
player.play_cards(cards)
notify(
[p.user.device for p in game.players if p.user.device and p != player],
'Politically Incorrect',
'Something happened in "{}"!'.format(game.name)
)
for p in game.players:
p.seen = False
player.seen = True
try:
db.session.commit()
except:
db.session.rollback()
return jsonify()
示例6: get_game
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import get [as 别名]
def get_game(id, user, content):
"""Returns a game in a format dependent on the game's status."""
game = Game.get(id)
player = Player.get(user, game)
if player not in [p for p in game.players if p.status != Player.REJECTED]:
return jsonify(
message='You can\'t see this game because you\'re not in it!'
), 418
if game.status == Game.PENDING:
return jsonify(**{
'id' : game.id,
'host' : {
'name' : game.host.name,
'email': game.host.email
},
'name' : game.name,
'max_points' : game.max_points,
'max_players': game.max_players,
'status' : game.status,
'players' : [
{
'name' : p.user.name,
'email' : p.user.email,
'picture': p.user.picture,
'status' : p.status,
'points' : 0
}
for p in game.players
]
})
elif game.status == Game.ONGOING:
if not player.seen:
player.seen = True
try:
db.session.commit()
except:
db.session.rollback()
raise
return jsonify(**{
'id' : game.id,
'host' : {
'name' : game.host.name,
'email': game.host.email
},
'name' : game.name,
'max_points' : game.max_points,
'max_players': game.max_players,
'status' : game.status,
'black_card' : {
'id' : game.black_card.id,
'text' : game.black_card.text,
'answers': game.black_card.answers
},
'table' : [
{
'name' : p.user.name,
'email' : p.user.email,
'picture': p.user.picture,
'cards' : [
{
'id' : card.id,
'text': card.text
}
for card in p.get_played()
]
}
for p in game.players
if p.played and p != game.judge
],
'hand' : [
{
'id' : card.id,
'text': card.text
}
for card in player.hand
],
'judge' : {
'name' : game.judge.user.name,
'email': game.judge.user.email,
},
'players' : [
{
'name' : p.user.name,
'email' : p.user.email,
'picture': p.user.picture,
'status' : p.status,
'points' : p.score
}
for p in game.players
],
'previous' : game.previous_round
})
elif game.status == Game.ENDED:
return jsonify(**{
#.........这里部分代码省略.........