Add unready toggle in lobby
- Server: Handle unready event to set player ready state to false - Client: Ready button toggles between READY and UNREADY - Client: Unready sends unready socket event to server Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+17
-6
@@ -118,6 +118,19 @@ io.on('connection', (socket) => {
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('unready', () => {
|
||||
const player = lobby.players.get(socket.id);
|
||||
if (!player) return;
|
||||
|
||||
player.ready = false;
|
||||
|
||||
// Broadcast only to players in the lobby room
|
||||
io.to(LOBBY_ROOM).emit('player-joined', {
|
||||
player: { id: player.id, name: player.name, ready: player.ready },
|
||||
players: getPlayersList()
|
||||
});
|
||||
});
|
||||
|
||||
socket.on('player-move', ({ playerId, direction }) => {
|
||||
if (!lobby.gameStarted) return;
|
||||
|
||||
@@ -367,14 +380,12 @@ function clearRows(player) {
|
||||
}
|
||||
|
||||
function sendGarbage(sender, rowsCleared) {
|
||||
const garbageRows = rowsCleared >= 4 ? rowsCleared : Math.max(1, rowsCleared - 1);
|
||||
// Number of garbage rows equals number of lines cleared
|
||||
const opponents = Array.from(lobby.players.values()).filter(p => p.id !== sender.id && !p.eliminated);
|
||||
if (opponents.length === 0) return;
|
||||
// Send all garbage rows to each opponent
|
||||
for (const opponent of opponents) {
|
||||
for (let i = 0; i < garbageRows; i++) {
|
||||
addGarbageToPlayer(opponent);
|
||||
}
|
||||
for (let i = 0; i < rowsCleared; i++) {
|
||||
const target = opponents[Math.floor(Math.random() * opponents.length)];
|
||||
addGarbageToPlayer(target);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user