本文整理匯總了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