-
-
Save parzibyte/3ecf01d16f9e254525cedf9e6168ed91 to your computer and use it in GitHub Desktop.
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
figureCanMoveRight() { | |
if (!this.currentFigure) return false; | |
for (const point of this.currentFigure.getPoints()) { | |
const newPoint = new Point(point.x + 1, point.y); | |
if (!this.isValidPoint(newPoint, this.currentFigure.getPoints())) { | |
return false; | |
} | |
} | |
return true; | |
} | |
figureCanMoveLeft() { | |
if (!this.currentFigure) return false; | |
for (const point of this.currentFigure.getPoints()) { | |
const newPoint = new Point(point.x - 1, point.y); | |
if (!this.isValidPoint(newPoint, this.currentFigure.getPoints())) { | |
return false; | |
} | |
} | |
return true; | |
} | |
figureCanMoveDown() { | |
if (!this.currentFigure) return false; | |
for (const point of this.currentFigure.getPoints()) { | |
const newPoint = new Point(point.x, point.y + 1); | |
if (!this.isValidPoint(newPoint, this.currentFigure.getPoints())) { | |
return false; | |
} | |
} | |
return true; | |
} | |
figureCanRotate() { | |
const newPointsAfterRotate = this.currentFigure.getNextRotation(); | |
for (const rotatedPoint of newPointsAfterRotate) { | |
if (!this.isValidPoint(rotatedPoint, this.currentFigure.getPoints())) { | |
return false; | |
} | |
} | |
return true; | |
} | |
rotateFigure() { | |
if (!this.figureCanRotate()) { | |
this.sounds.denied.currentTime = 0; | |
this.sounds.denied.play(); | |
return; | |
} | |
this.currentFigure.points = this.currentFigure.getNextRotation(); | |
this.currentFigure.incrementRotationIndex(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment