本文整理汇总了Python中models.Game.create方法的典型用法代码示例。如果您正苦于以下问题:Python Game.create方法的具体用法?Python Game.create怎么用?Python Game.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Game
的用法示例。
在下文中一共展示了Game.create方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import create [as 别名]
def generate():
players = int(raw_input('Players: '))
amount = int(raw_input('Amount of games: '))
headers = {
'X-Mashape-Key': 'C4UDpRLdVnmshrlrYUufHIF1VDgBp1yrTvejsnoNyCbSYgzbuc',
'Accept': 'application/json',
'Content-Type': 'application/json'
}
for i in range(amount):
r = requests.get('https://bingo.p.mashape.com/index.php?cards_number={0}'.format(players), headers=headers)
data = json.loads(r.text)
game = Game()
game.create(players, data)
db.session.add(game)
db.session.commit()
print('Generated game {0} for {1} players..'.format(game, game.players))
示例2: create_game
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import create [as 别名]
def create_game(self, request, **kwargs):
""" If the current user is an admin, create a new game containing the provided players """
if not request.user_messages:
raise endpoints.BadRequestException("You must specify which players will be participating in the game")
player_emails = []
for i in request.user_messages:
if i.email in player_emails:
raise endpoints.BadRequestException("Duplicate email address: {}".format(i))
player_emails.append(i.email)
if len(player_emails) < 2:
raise endpoints.BadRequestException("You must submit at least two players")
game = Game.create(player_emails)
return create_game_id_message(game.key.id())
示例3: create_game
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import create [as 别名]
def create_game(user, content):
"""Creates a pending game."""
name = content['name']
max_points = max(content['max_points'], 5)
max_players = content['max_players']
random = content['random']
emails = content['emails']
if len(emails) < 3:
return jsonify(message='You need to invite more people!'), 418
game = Game.create(
user, name, max_points, min(max_players, len(emails) + 1), random
)
users = User.get_all(emails) + [user]
players = Player.create_all(users, game)
player = next(
(player for player in players if player.user == user),
None
)
player.set_status_joined()
notify(
[u.device for u in users if u != user],
'Politically Incorrect',
'You\'ve been invited to a game: "{}"!'.format(name)
)
try:
db.session.commit()
except:
db.session.rollback()
raise
return jsonify(**{
'id' : game.id,
'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,
'status': p.status
}
for p in game.players
]
})