Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created November 2, 2020 17:28
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/58f0bc55d9b7141f1e82b0d61af3a230 to your computer and use it in GitHub Desktop.
Save parzibyte/58f0bc55d9b7141f1e82b0d61af3a230 to your computer and use it in GitHub Desktop.
class Tetromino {
constructor(rotations) {
this.rotations = rotations;
this.rotationIndex = 0;
this.points = this.rotations[this.rotationIndex];
const randomColor = Utils.getRandomColor();
this.rotations.forEach(points => {
points.forEach(point => {
point.color = randomColor;
});
});
this.incrementRotationIndex();
}
getPoints() {
return this.points;
}
incrementRotationIndex() {
if (this.rotations.length <= 0) {
this.rotationIndex = 0;
} else {
if (this.rotationIndex + 1 >= this.rotations.length) {
this.rotationIndex = 0;
} else {
this.rotationIndex++;
}
}
}
getNextRotation() {
return this.rotations[this.rotationIndex];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment