Fix elimination check to only eliminate when piece blocks are above visible area

Previously, players were eliminated when currentPiece.y <= 0, which was too
aggressive. Pieces like I, T, S, Z, J, L spawn at y=0 but have empty top rows,
so their actual blocks are at y >= 1 and visible on the board.

Now we check if any part of the locked piece is actually above y=0 (not
visible) before eliminating the player.
This commit is contained in:
2026-03-21 03:05:35 +00:00
parent e3f594e44e
commit ada9ce73fa
+15 -1
View File
@@ -226,7 +226,21 @@ class TetrisGame {
}
// Check for game over (piece locked above visible area)
if (this.currentPiece.y <= 0) {
// Only eliminate if any part of the piece is above y=0 (not visible)
let pieceAboveBoard = false;
for (let row = 0; row < this.currentPiece.shape.length; row++) {
for (let col = 0; col < this.currentPiece.shape[row].length; col++) {
if (this.currentPiece.shape[row][col]) {
const boardY = this.currentPiece.y + row;
if (boardY < 0) {
pieceAboveBoard = true;
break;
}
}
}
if (pieceAboveBoard) break;
}
if (pieceAboveBoard) {
this.gameOver = true;
this.eliminated = true;
}