-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsquare.js
More file actions
38 lines (34 loc) · 977 Bytes
/
Copy pathsquare.js
File metadata and controls
38 lines (34 loc) · 977 Bytes
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
export default class Square {
constructor(pos, ctx, sideLength, xOffset, yOffset) {
this.pos = pos;
this.xOffset = xOffset;
this.yOffset = yOffset;
this.ctx = ctx;
this.height = sideLength;
this.width = sideLength;
}
draw(isSelected, isLegalMove, movedFrom, movedTo) {
const column = this.pos % 10;
const row = Math.floor(this.pos / 10);
if (column > 0 && row > 0 && column < 9 && row < 9) {
if (isSelected) {
this.ctx.fillStyle = 'gold';
} else if ((column + row) % 2) {
this.ctx.fillStyle = 'gainsboro';
} else {
this.ctx.fillStyle = 'white';
}
} else {
this.ctx.fillStyle = 'black';
}
if (movedFrom) {
this.ctx.fillStyle = '#dbad6a';
} else if (movedTo) {
this.ctx.fillStyle = '#dbad6a';
}
if (isLegalMove) {
this.ctx.fillStyle = '#b470c3';
}
this.ctx.fillRect(this.xOffset, this.yOffset, this.width, this.height);
}
}