Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created November 2, 2020 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/2556116054c7447b328f9dd334b5cbb2 to your computer and use it in GitHub Desktop.
Save parzibyte/2556116054c7447b328f9dd334b5cbb2 to your computer and use it in GitHub Desktop.
verifyAndDeleteFullRows() {
const yCoordinates = this.getPointsToDelete();
if (yCoordinates.length <= 0) return;
this.addScore(yCoordinates);
this.sounds.success.currentTime = 0;
this.sounds.success.play();
this.changeDeletedRowColor(yCoordinates);
this.canPlay = false;
setTimeout(() => {
this.sounds.success.pause();
this.removeRowsFromExistingPieces(yCoordinates);
this.syncExistingPiecesWithBoard();
const invertedCoordinates = Array.from(yCoordinates);
// Now the coordinates are in descending order
invertedCoordinates.reverse();
for (let coordenadaY of invertedCoordinates) {
for (let y = Game.ROWS - 1; y >= 0; y--) {
for (let x = 0; x < this.existingPieces[y].length; x++) {
if (y < coordenadaY) {
let contador = 0;
let yAuxiliar = y;
while (this.isEmptyPoint(x, yAuxiliar + 1) && !this.absolutePointOutOfLimits(x, yAuxiliar + 1) && contador < yCoordinates.length) {
this.existingPieces[yAuxiliar + 1][x] = this.existingPieces[yAuxiliar][x];
this.existingPieces[yAuxiliar][x] = {
color: Game.EMPTY_COLOR,
taken: false,
}
this.syncExistingPiecesWithBoard();
contador++;
yAuxiliar++;
}
}
}
}
}
this.syncExistingPiecesWithBoard()
this.canPlay = true;
}, Game.DELETE_ROW_ANIMATION);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment