-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtile.js
More file actions
34 lines (32 loc) · 1.11 KB
/
tile.js
File metadata and controls
34 lines (32 loc) · 1.11 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
class Tile {
constructor(index) {
this.index = index;
this.x = index % 9;
this.y = Math.trunc(index / 9);
this.value = 0;
this.mutable = true;
this.isHighlighted = false;
}
render() {
ctx.fillStyle = "white";
ctx.fillRect(this.x * cellSize, this.y * cellSize, cellSize, cellSize);
if (!this.mutable) {
ctx.fillStyle = "#afeeee";
ctx.fillRect(this.x * cellSize, this.y * cellSize, cellSize, cellSize);
}
if (this.isHighlighted) {
ctx.fillStyle = "#00ff00";
ctx.fillRect(this.x * cellSize, this.y * cellSize, cellSize, cellSize);
}
if (this.index == selectedIndex) {
ctx.fillStyle = "#ff0000";
ctx.fillRect(this.x * cellSize, this.y * cellSize, cellSize, cellSize);
}
ctx.font = "60px Verdana";
ctx.textAlign = "center";
ctx.fillStyle = "#000000";
if (this.value != 0) {
ctx.fillText(this.value, (this.x * cellSize) + (cellSize * 0.5), (this.y * cellSize) + (cellSize * 0.75));
}
}
}