-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses.js
More file actions
81 lines (71 loc) · 1.69 KB
/
Copy pathclasses.js
File metadata and controls
81 lines (71 loc) · 1.69 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
class HexoNet {
net;
domains = new Set();
constructor(l, m, n) {
this.l = l;
this.m = m;
this.n = n;
this.net = new Array(l + m - 1);
for (let i = 0; i < l + m - 1; i++) {
let rowLen;
if (i < Math.min(l, m))
rowLen = n + i
else if (i < Math.max(m, l))
rowLen = n + Math.min(l, m) - 1;
else
rowLen = n + l - 2 - i + m;
this.net[i] = new Array(rowLen);
for (let j = 0; j < rowLen; j++)
this.net[i][j] = new Hexo((i < l - 1) ? j + l - i - 1 : j, i);
}
}
get(x, y) {
if (x == undefined || y == undefined) return undefined;
let offsetX = 0;
if (y < this.l - 1) {
offsetX = this.l - y - 1;
}
if (y < 0 || y > this.net.length - 1
|| x - offsetX < 0 || x - offsetX > this.net[y].length - 1)
return undefined;
return this.net[y][x - offsetX];
}
array() {
return this.net.flat();
}
}
class Hexo {
state = 0;
domain;
constructor(x, y) {
this.x = x;
this.y = y;
}
color() {
return this.domain?.color || "#ffffff";
}
changeState() {
this.domain = undefined;
this.state = this.state ? 0 : 1;
}
}
class Area {
hexs = new Set();
constructor() {
}
join(area) {
area.hexs.forEach(hex => this.add(hex));
return this;
}
add(hex) {
hex.domain = this;
this.hexs.add(hex);
return this;
}
}
class Domain extends Area {
constructor() {
super();
this.color = newColor();
}
}