xxxxxxxxxx
63
class Cell {
constructor(x, y) {
this.x = x;
this.y = y;
this.d = width / 6;
this.player = 0;
this.exploded = false;
}
explode() {
this.exploded = true;
}
show() {
if (this.player == 0) {
fill(255, 100);
} else if (this.player == 1) {
fill(0, 0, 255, 100);
} else if (this.player == 2) {
fill(255, 0, 0, 100);
}
strokeWeight(1);
stroke(255);
ellipse(this.x, this.y, this.d);
if (this.player !== 0) {
fill(255);
textSize(width / 12);
textAlign(CENTER, CENTER);
text(this.value, this.x, this.y);
}
if (this.exploded) {
strokeWeight(3);
stroke(255, 0, 0)
line(this.x - this.d / 2, this.y - this.d / 2, this.x + this.d / 2, this.y + this.d / 2);
line(this.x + this.d / 2, this.y - this.d / 2, this.x - this.d / 2, this.y + this.d / 2);
}
}
checkPressed() {
if (mouseX > this.x - this.d / 2 &&
mouseX < this.x + this.d / 2 &&
mouseY > this.y - this.d / 2 &&
mouseY < this.y + this.d / 2 &&
this.player == 0) {
if (number !== 11) {
this.value = number;
this.player = turn;
if (turn == 1) {
turn = 2;
} else {
turn = 1;
}
if (this.player == 2) {
number++;
}
} else {
this.explode();
}
}
}
}