本文整理汇总了Python中game.models.Game.create_new_game方法的典型用法代码示例。如果您正苦于以下问题:Python Game.create_new_game方法的具体用法?Python Game.create_new_game怎么用?Python Game.create_new_game使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类game.models.Game
的用法示例。
在下文中一共展示了Game.create_new_game方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from game.models import Game [as 别名]
# 或者: from game.models.Game import create_new_game [as 别名]
def setUp(self):
server = MockSocketIOServer()
self.environ = {}
socket = MockSocket(server, {})
self.environ['socketio'] = socket
self.ns = GameNamespace(self.environ, '/game')
# Create mock objects for testing the socket
self.ns.emit = MagicMock()
self.ns.broadcast_to_room = MagicMock()
self.ns.emit_to_room = MagicMock()
self.ns.get_time = MagicMock(return_value=12242012)
# Create a game with one user
User.objects.create_user("hosting_player", "email", "password")
self.user = authenticate(username="hosting_player", password="password")
self.aMap = Map(creator=self.user, num_players=3, data="{}", map_name="Oogie Boogie")
self.aMap.save()
self.game, self.players_json = Game.create_new_game(self.aMap.id, self.user)
self.ns.request = MockRequest()
self.ns.request.user = self.user
self.ns.request.META = {
'QUERY_STRING': 'id=' + str(self.game.id)
}
示例2: test_add_user_to_game
# 需要导入模块: from game.models import Game [as 别名]
# 或者: from game.models.Game import create_new_game [as 别名]
def test_add_user_to_game(self):
game, _ = Game.create_new_game(self.aMap.id, self.user)
# Perform the join logic
_, players_json, player_id = Game.add_user_to_game(game.id, self.joiner)
# Check a bunch of conditions
self.assertEqual(len(players_json), 3)
self.assertEqual(players_json[0], "hosting_player")
self.assertEqual(players_json[1], "joining_player")
示例3: post
# 需要导入模块: from game.models import Game [as 别名]
# 或者: from game.models.Game import create_new_game [as 别名]
def post(self, request):
""" Create a new game """
form = GameForm(request.POST)
if form.is_valid():
game, players_json = Game.create_new_game(form.cleaned_data["map_id"], request.user)
# Render the context with our parameters.
return redirect(reverse("game_view", kwargs={"gameid": game.id}))
else:
# Needs better error handling
raise Http404
示例4: test_create_new_game
# 需要导入模块: from game.models import Game [as 别名]
# 或者: from game.models.Game import create_new_game [as 别名]
def test_create_new_game(self):
game, players_json = Game.create_new_game(self.aMap.id, self.user)
self.assertEqual(len(players_json), 3)
self.assertEqual(players_json[0], "hosting_player")
pass