forked from dmitastr/solitare_triangle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pin.js
55 lines (47 loc) · 1.28 KB
/
pin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
class Pin {
constructor(x, y, r, row, idx) {
this.x = x;
this.y = y;
this.r = r;
this.empty = false;
this.active = false;
this.colorNotEmpty = 50;
this.colorEmpty = 255;
this.borderNotActive = 0;
this.borderActive = color(255, 204, 0);
this.row = row;
this.idx = idx;
}
show() {
if (this.active) {
stroke(this.borderActive);
} else {
stroke(this.borderNotActive);
}
if (this.empty) {
fill(this.colorEmpty);
} else {
fill(this.colorNotEmpty);
}
strokeWeight(5);
ellipse(this.x, this.y, this.r);
}
select() {
this.active = !this.active;
}
isNeighbor(other) {
if (this.row===other.row) {
if (Math.abs(this.idx - other.idx)<=2) {
return this.idx - other.idx;
} else {
return 0;
}
} else {
if (Math.abs(this.row-other.row)<=2 && ((this.idx===other.idx) || (this.idx-other.idx)===(this.row-other.row))) {
return this.row-other.row;
} else {
return 0;
}
}
}
}