Create Ending
All checks were successful
Publish Docker image / Push Docker image to Docker Hub (push) Successful in 1m36s

This commit is contained in:
2025-03-01 18:07:38 +01:00
parent 09fb1e3938
commit 032ebc2368
7 changed files with 270 additions and 28 deletions

View File

@@ -109,6 +109,23 @@ module.exports = (io) => (socket) => {
io.to(roomId).emit('round-results', results);
};
const handleNextRound = async (roomId) => {
try {
const result = await gameController.startNewRound(roomId);
if (result.gameEnd) {
const finalData = gameController.getFinalScores(roomId);
io.to(roomId).emit('game-ended', finalData);
return;
}
handleRoundStart(roomId);
} catch (error) {
console.error("Error starting next round:", error);
socket.emit("error", { message: "Failed to start next round due to an error" });
}
};
socket.on("disconnect", () => {
const roomId = roomController.getUserRoom(socket.id);
if (roomId) {
@@ -298,17 +315,7 @@ module.exports = (io) => (socket) => {
return socket.emit("error", { message: "At least 2 players are required" });
}
try {
const success = await gameController.startNewRound(roomId);
if (success) {
handleRoundStart(roomId);
} else {
socket.emit("error", { message: "Failed to start next round" });
}
} catch (error) {
console.error("Error starting next round:", error);
socket.emit("error", { message: "Failed to start next round due to an error" });
}
await handleNextRound(roomId);
});
socket.on("get-current-frequency", () => {