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

@ -44,6 +44,8 @@ const initializeGameState = (roomId) => {
return gameStates[roomId];
};
const MAX_ROUNDS = 5;
const startNewRound = async (roomId) => {
const gameState = gameStates[roomId];
if (!gameState) return false;
@ -52,6 +54,11 @@ const startNewRound = async (roomId) => {
if (users.length < 2) return false;
gameState.round += 1;
if (gameState.round > MAX_ROUNDS) {
return { gameEnd: true, finalScores: gameState.scores };
}
gameState.phase = 'composing';
gameState.guessResults = {};
gameState.roundStartTime = Date.now();
@ -83,7 +90,6 @@ const determineNextComposer = (roomId, gameState, users) => {
return users[(currentIndex + 1) % users.length].id;
};
// Then modify the selectSongAndOptions function to use the shuffle:
const selectSongAndOptions = async (gameState) => {
try {
console.log(`Fetching songs from playlist: ${gameState.selectedPlaylist}`);
@ -107,7 +113,6 @@ const selectSongAndOptions = async (gameState) => {
count++;
}
// Shuffle the song options to randomize the position of the correct answer
gameState.songOptions = shuffleArray(Array.from(optionIds).map(id => ({ id })));
return true;
@ -219,6 +224,27 @@ const getGameState = (roomId) => {
return gameStates[roomId] || null;
};
const getFinalScores = (roomId) => {
const gameState = gameStates[roomId];
if (!gameState) return null;
const users = roomController.getRoomUsers(roomId);
const finalScores = {};
Object.entries(gameState.scores).forEach(([userId, score]) => {
const user = users.find(u => u.id === userId);
finalScores[userId] = {
score: score,
name: user?.name || "Player"
};
});
return {
scores: finalScores,
lastRound: gameState.round
};
};
module.exports = {
initializeGameState,
startNewRound,
@ -234,5 +260,7 @@ module.exports = {
getSelectedSong,
cleanupGameState,
getCurrentComposer,
getGameState
getGameState,
getFinalScores,
MAX_ROUNDS
};