當前位置: 首頁>>代碼示例>>Python>>正文


Python Game.add_user_to_game方法代碼示例

本文整理匯總了Python中game.models.Game.add_user_to_game方法的典型用法代碼示例。如果您正苦於以下問題:Python Game.add_user_to_game方法的具體用法?Python Game.add_user_to_game怎麽用?Python Game.add_user_to_game使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在game.models.Game的用法示例。


在下文中一共展示了Game.add_user_to_game方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: on_join

# 需要導入模塊: from game.models import Game [as 別名]
# 或者: from game.models.Game import add_user_to_game [as 別名]
    def on_join(self):
        game_id = self.session['game_id']
        user = self.session['user']
        # Join the game_id room on the sockets side
        self.join(str(game_id))

        # Add the user to the game on the database side
        game, players_json, player_id = Game.add_user_to_game(game_id, user)

        self.session['player_id'] = player_id

        # The host of the game is the person that created the game
        # WHICH HAPPENS TO BE player_id == 0 IN OUR IMPLEMENTATION
        # Perhaps we should fix this one day
        isHost = self.session['isHost'] = (player_id == 0)
        player_list = [v for v in players_json]

        # Send the new player information needed to join the map
        selfData = {
            'isHost': isHost,
            'map_id': game.map.id,
            'player_list': player_list,
            'player_id': player_id
        }
        self.emit('game_data', selfData)

        # Send all other players information needed to add the current
        # player to the game
        data = {
            'username': user.username,
            'timestamp': self.get_time(),
            'player_id': self.session['player_id']
        }
        self.emit_to_room(str(self.session['game_id']), 'join', data)
開發者ID:hellochar,項目名稱:the_game_bazaar,代碼行數:36,代碼來源:sockets.py

示例2: test_add_user_to_game

# 需要導入模塊: from game.models import Game [as 別名]
# 或者: from game.models.Game import add_user_to_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


注:本文中的game.models.Game.add_user_to_game方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。