Fix game over condition and garbage row placement

- Remove premature elimination in addGarbageToPlayer (top rows check)
- Remove redundant y < 0 elimination check in lockPiece
- Players are only eliminated when spawnPiece fails (board full)
- Garbage rows now added to bottom of board, pushing blocks up
This commit is contained in:
2026-03-20 07:53:08 -07:00
parent 833256d18f
commit f9cafe630c
+4 -13
View File
@@ -250,8 +250,6 @@ function lockPiece(player) {
}
}
if (player.currentPiece.y <= 0) player.eliminated = true;
const rowsCleared = clearRows(player);
if (!spawnPiece(player)) player.eliminated = true;
@@ -293,19 +291,12 @@ function sendGarbage(sender, rowsCleared) {
}
function addGarbageToPlayer(player) {
player.board.pop();
// Remove top row and add garbage to bottom
player.board.shift();
const garbageRow = Array(BOARD_WIDTH).fill(GARBAGE_COLOR);
garbageRow[Math.floor(Math.random() * BOARD_WIDTH)] = 0;
player.board.unshift(garbageRow);
for (let row = 0; row < 2; row++) {
for (let col = 0; col < BOARD_WIDTH; col++) {
if (player.board[row][col] !== 0) {
player.eliminated = true;
return;
}
}
}
player.board.push(garbageRow);
// Elimination is handled by spawnPiece when a new piece can't fit
}
function startGame() {