le caca coule au cucu
This commit is contained in:
parent
602d4f300f
commit
a6c27fc87a
@ -210,7 +210,7 @@ class ChatNoticeConsumer(WebsocketConsumer):
|
|||||||
if (targets[0] in self.channel_layer.invite[user.pk]):
|
if (targets[0] in self.channel_layer.invite[user.pk]):
|
||||||
self.channel_layer.invite[user.pk].remove(targets[0])
|
self.channel_layer.invite[user.pk].remove(targets[0])
|
||||||
|
|
||||||
id_game = GameModel().create([user.pk, targets[0]]);
|
id_game = GameModel().create("pong", [user.pk, targets[0]]);
|
||||||
|
|
||||||
return 200, id_game
|
return 200, id_game
|
||||||
|
|
||||||
|
@ -21,8 +21,9 @@ class Game
|
|||||||
* @param {Boolean} started
|
* @param {Boolean} started
|
||||||
* @param {Number} winner_id
|
* @param {Number} winner_id
|
||||||
* @param {String} state
|
* @param {String} state
|
||||||
|
* @param {String} gamemode
|
||||||
*/
|
*/
|
||||||
constructor(client, id, disconnect_handler, goal_handler, finish_handler, winner_id, state, started, finished, players_data, start_timestamp, stop_timestamp)
|
constructor(client, id, disconnect_handler, goal_handler, finish_handler, winner_id, state, started, finished, players_data, start_timestamp, stop_timestamp, gamemode)
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @type {Client}
|
* @type {Client}
|
||||||
@ -94,6 +95,11 @@ class Game
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {String}
|
||||||
|
*/
|
||||||
|
this.gamemode = gamemode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -92,8 +92,7 @@ const router = async(uri) => {
|
|||||||
{ path: "/matchmaking", view: MatchMakingView },
|
{ path: "/matchmaking", view: MatchMakingView },
|
||||||
{ path: "/games/offline", view: GameOfflineView },
|
{ path: "/games/offline", view: GameOfflineView },
|
||||||
{ path: "/tictactoe", view: TicTacToeView },
|
{ path: "/tictactoe", view: TicTacToeView },
|
||||||
{ path: "/games/:id/0", view: GameView2D },
|
{ path: "/games/pong/:id", view: GameView2D },
|
||||||
{ path: "/games/:id/1", view: GameView3D },
|
|
||||||
{ path: "/games/tictactoe/:id", view: TicTacToeOnlineView },
|
{ path: "/games/tictactoe/:id", view: TicTacToeOnlineView },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -15,8 +15,10 @@ class GameModel(models.Model):
|
|||||||
winner_id = models.IntegerField(default = -1)
|
winner_id = models.IntegerField(default = -1)
|
||||||
start_timestamp = models.BigIntegerField(null = True, blank = True)
|
start_timestamp = models.BigIntegerField(null = True, blank = True)
|
||||||
stop_timestamp = models.BigIntegerField(null = True, blank = True)
|
stop_timestamp = models.BigIntegerField(null = True, blank = True)
|
||||||
|
gamemode = models.CharField(max_length = 60, default = "pong")
|
||||||
|
|
||||||
def create(self, players_id: [int]):
|
def create(self, gamemode: str, players_id: [int]):
|
||||||
|
self.gamemode = gamemode
|
||||||
self.save()
|
self.save()
|
||||||
for player_id in players_id:
|
for player_id in players_id:
|
||||||
GameMembersModel(game_id = self.pk, player_id = player_id).save()
|
GameMembersModel(game_id = self.pk, player_id = player_id).save()
|
||||||
|
@ -14,10 +14,11 @@ class GameSerializer(serializers.ModelSerializer):
|
|||||||
finished = serializers.ReadOnlyField()
|
finished = serializers.ReadOnlyField()
|
||||||
start_timestamp = serializers.ReadOnlyField()
|
start_timestamp = serializers.ReadOnlyField()
|
||||||
stop_timestamp = serializers.ReadOnlyField()
|
stop_timestamp = serializers.ReadOnlyField()
|
||||||
|
gamemode = serializers.ReadOnlyField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = GameModel
|
model = GameModel
|
||||||
fields = ["id", "winner_id", "state", "started", "finished", "players", "start_timestamp", "stop_timestamp"]
|
fields = ["id", "winner_id", "state", "started", "finished", "players", "start_timestamp", "stop_timestamp", "gamemode"]
|
||||||
|
|
||||||
def get_state(self, instance: GameModel):
|
def get_state(self, instance: GameModel):
|
||||||
if (instance.finished):
|
if (instance.finished):
|
||||||
|
@ -39,9 +39,9 @@ class MatchMaking(WebsocketConsumer):
|
|||||||
self.disconnect(1000)
|
self.disconnect(1000)
|
||||||
return
|
return
|
||||||
|
|
||||||
if (self.mode < 2 or self.mode > 4):
|
if (self.gamemode not in ["tictactoe", "pong"]):
|
||||||
data: dict = {
|
data: dict = {
|
||||||
"detail": "The mode must be > 1 and < 4.",
|
"detail": "The gamemode must 'pong' or 'tictactoe'.",
|
||||||
}
|
}
|
||||||
self.send(json.dumps(data))
|
self.send(json.dumps(data))
|
||||||
self.disconnect(1000)
|
self.disconnect(1000)
|
||||||
@ -49,8 +49,8 @@ class MatchMaking(WebsocketConsumer):
|
|||||||
|
|
||||||
waiting_room.broadcast(f"{len(waiting_room)} / {waiting_room.mode}")
|
waiting_room.broadcast(f"{len(waiting_room)} / {waiting_room.mode}")
|
||||||
if (len(waiting_room) == waiting_room.mode):
|
if (len(waiting_room) == waiting_room.mode):
|
||||||
game_id: int = GameModel().create(waiting_room.get_users_id())
|
game_id: int = GameModel().create(self.gamemode, waiting_room.get_users_id())
|
||||||
waiting_room.broadcast("game_found", {"game_id": game_id})
|
waiting_room.broadcast("game_found", {"game_id": game_id, "gamemode": self.gamemode})
|
||||||
waiting_room.clear()
|
waiting_room.clear()
|
||||||
|
|
||||||
def disconnect(self, close_code):
|
def disconnect(self, close_code):
|
||||||
|
@ -19,9 +19,10 @@ class TournamentModel(models.Model):
|
|||||||
level = models.IntegerField()
|
level = models.IntegerField()
|
||||||
started = models.BooleanField(default = False)
|
started = models.BooleanField(default = False)
|
||||||
finished = models.BooleanField(default = False)
|
finished = models.BooleanField(default = False)
|
||||||
|
gamemode = models.CharField(max_length = 50, default = "pong")
|
||||||
|
|
||||||
def create_game(self, level, players_id):
|
def create_game(self, level, players_id):
|
||||||
game_id = GameModel().create(players_id = players_id)
|
game_id = GameModel().create(self.gamemode, players_id = players_id)
|
||||||
TournamentGamesModel(game_id = game_id, tournament_id = self.pk, tournament_level = level).save()
|
TournamentGamesModel(game_id = game_id, tournament_id = self.pk, tournament_level = level).save()
|
||||||
return game_id
|
return game_id
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user