le caca coule au cucu

This commit is contained in:
starnakin 2024-03-25 16:11:07 +01:00 committed by AdrienLSH
parent 602d4f300f
commit a6c27fc87a
7 changed files with 20 additions and 11 deletions

View File

@ -210,7 +210,7 @@ class ChatNoticeConsumer(WebsocketConsumer):
if (targets[0] in self.channel_layer.invite[user.pk]):
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

View File

@ -21,8 +21,9 @@ class Game
* @param {Boolean} started
* @param {Number} winner_id
* @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}
@ -94,6 +95,11 @@ class Game
)
);
});
/**
* @type {String}
*/
this.gamemode = gamemode;
}
/**

View File

@ -92,8 +92,7 @@ const router = async(uri) => {
{ path: "/matchmaking", view: MatchMakingView },
{ path: "/games/offline", view: GameOfflineView },
{ path: "/tictactoe", view: TicTacToeView },
{ path: "/games/:id/0", view: GameView2D },
{ path: "/games/:id/1", view: GameView3D },
{ path: "/games/pong/:id", view: GameView2D },
{ path: "/games/tictactoe/:id", view: TicTacToeOnlineView },
];

View File

@ -15,8 +15,10 @@ class GameModel(models.Model):
winner_id = models.IntegerField(default = -1)
start_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()
for player_id in players_id:
GameMembersModel(game_id = self.pk, player_id = player_id).save()

View File

@ -14,10 +14,11 @@ class GameSerializer(serializers.ModelSerializer):
finished = serializers.ReadOnlyField()
start_timestamp = serializers.ReadOnlyField()
stop_timestamp = serializers.ReadOnlyField()
gamemode = serializers.ReadOnlyField()
class Meta:
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):
if (instance.finished):

View File

@ -39,9 +39,9 @@ class MatchMaking(WebsocketConsumer):
self.disconnect(1000)
return
if (self.mode < 2 or self.mode > 4):
if (self.gamemode not in ["tictactoe", "pong"]):
data: dict = {
"detail": "The mode must be > 1 and < 4.",
"detail": "The gamemode must 'pong' or 'tictactoe'.",
}
self.send(json.dumps(data))
self.disconnect(1000)
@ -49,8 +49,8 @@ class MatchMaking(WebsocketConsumer):
waiting_room.broadcast(f"{len(waiting_room)} / {waiting_room.mode}")
if (len(waiting_room) == waiting_room.mode):
game_id: int = GameModel().create(waiting_room.get_users_id())
waiting_room.broadcast("game_found", {"game_id": game_id})
game_id: int = GameModel().create(self.gamemode, waiting_room.get_users_id())
waiting_room.broadcast("game_found", {"game_id": game_id, "gamemode": self.gamemode})
waiting_room.clear()
def disconnect(self, close_code):

View File

@ -19,9 +19,10 @@ class TournamentModel(models.Model):
level = models.IntegerField()
started = models.BooleanField(default = False)
finished = models.BooleanField(default = False)
gamemode = models.CharField(max_length = 50, default = "pong")
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()
return game_id