diff --git a/public/js/app.js b/public/js/app.js index 03e120e..e0c0347 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -70,13 +70,8 @@ function setupNetworkListeners() { localGame.loadState(localState); } - // Check for game over - const allStates = network.getAllGameStates(); - const activePlayers = Object.values(allStates).filter(s => !s.eliminated); - - if (activePlayers.length <= 1) { - endGame(allStates); - } + // Game over is handled by the server via 'game-over' event + // Don't check locally to avoid premature game end }); // Game over diff --git a/server/index.js b/server/index.js index c3c53a7..96c5b81 100644 --- a/server/index.js +++ b/server/index.js @@ -590,7 +590,9 @@ function getStates() { function checkGameOver() { const activePlayers = Array.from(lobby.players.values()).filter(p => !p.eliminated); + console.log(`[GAMEOVER CHECK] Active players: ${activePlayers.length} (${activePlayers.map(p => p.name).join(', ')})`); if (activePlayers.length <= 1) { + console.log(`[GAME OVER] ${activePlayers.length === 1 ? `Winner: ${activePlayers[0].name}` : 'No winner (all eliminated)'}`); io.to(LOBBY_ROOM).emit('game-over', { states: getStates() }); if (lobby.gameInterval) { clearInterval(lobby.gameInterval);