xxxxxxxxxx
52
class Box {
constructor() {
let a = int(random(10, 49));
let b = int(random(10, 49));
this.q = new Question(107, 213, 50, 2, a, b);
this.a1 = new Answer(250, 71, 50, 2, a + b - 10);
this.a2 = new Answer(321, 71, 50, 2, a + b);
this.a3 = new Answer(392, 71, 50, 2, a + b + 10, 1);
this.indicated = false;
}
update() {
[this.q, this.a1, this.a2, this.a3].forEach(function(e) {
e.update();
})
}
display() {
[this.q, this.a1, this.a2, this.a3].forEach(function(e) {
e.display(color(255, 215, 0), color(31));
})
}
to_delete() {
return this.q.to_delete();
}
check_answer(x) {
if (!this.indicated) {
let right = this.a2.intersect(x);
let ra1 = this.a1.intersect(x);
let ra3 = this.a3.intersect(x);
if (right || ra1 || ra3) {
this.indicated = true;
if (ra1) this.a1.indicate(2);
if (right) this.a2.indicate(1);
if (ra3) this.a3.indicate(2);
}
return right;
}
return false;
}
intersect(y) {
let p = this.q.get_y();
return (p[0] <= y && p[1] >= y);
}
}