本文整理汇总了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)
示例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")