This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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