Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created November 2, 2020 18:11
Embed
What would you like to do?
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