当前位置: 首页>>代码示例>>Python>>正文


Python Game.create_new_game方法代码示例

本文整理汇总了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)
        }
开发者ID:hellochar,项目名称:the_game_bazaar,代码行数:29,代码来源:tests.py

示例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")
开发者ID:hellochar,项目名称:the_game_bazaar,代码行数:12,代码来源:tests.py

示例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
开发者ID:hellochar,项目名称:the_game_bazaar,代码行数:13,代码来源:views.py

示例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
开发者ID:hellochar,项目名称:the_game_bazaar,代码行数:7,代码来源:tests.py


注:本文中的game.models.Game.create_new_game方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。