本文整理汇总了Python中models.Game.create_game方法的典型用法代码示例。如果您正苦于以下问题:Python Game.create_game方法的具体用法?Python Game.create_game怎么用?Python Game.create_game使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Game
的用法示例。
在下文中一共展示了Game.create_game方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_game
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import create_game [as 别名]
def create_game(self, request):
""" Creates a new game.
This function creates a new game.
(NB: Games are just shells for questions. See the supplied readme
for more information.)
Returns:
GameForm -- a GameForm representation of the created game
"""
# Get player by username
player = get_player(request.user_name)
# Create the game
game = Game.create_game(player=player.key, title=request.title)
# Return confirmation of game creation
return game.to_form()
示例2: form_valid
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import create_game [as 别名]
def form_valid(self, form):
session_details = self.request.session.get('session_details', {}) # FIXME
# FIXME if not a dict, make it a dict (upgrade old content)
log.logger.debug('session_details %r', session_details)
existing_game = True
# Set the game properties in the database and session
game_name = form.cleaned_data['new_game']
if game_name:
# Attempting to create a new game
try:
# see if already exists
existing_game = Game.objects.get(name=game_name)
except Game.DoesNotExist:
existing_game = None
if not existing_game:
# really a new game
tmp_game = Game(name=form.cleaned_data['new_game'])
new_game = tmp_game.create_game(form.cleaned_data['card_set'])
tmp_game.gamedata = new_game
tmp_game.save()
self.game = tmp_game
if existing_game:
if not game_name:
game_name = form.cleaned_data.get('game_list')
existing_game = Game.objects.get(name=game_name) # existing_game maybe a bool
log.logger.debug('existing_game.gamedata %r',
(existing_game.gamedata,)
)
log.logger.debug('existing_game.gamedata players %r',
(existing_game.gamedata['players'],)
)
existing_game.save()
# Set the player session details
session_details['game'] = game_name
self.request.session['session_details'] = session_details # this is probably kinda dumb.... Previously we used seperate session items for game and user name and that maybe what we need to go back to
return super(LobbyView, self).form_valid(form)
示例3: trigger_start
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import create_game [as 别名]
def trigger_start():
Game.create_game()