-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCell.js
55 lines (47 loc) · 1.22 KB
/
Cell.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
export default class Cell {
constructor(x,y,w) {
this.x = x;
this.y = y;
this.w = w;
this.visible = false;
this.bomb = false;
this.distance = 0;
}
show (context) {
context.fillStyle = '#666';
context.fillRect( (this.x*this.w)+1, (this.y*this.w)+1, this.w-1, this.w-1); // couse is a square =P
if(this.visible){
context.fillStyle = (this.bomb)? '#900' : '#ddd';
context.fillRect( (this.x*this.w)+1, (this.y*this.w)+1, this.w-1, this.w-1); // couse is a square =P
if(!this.bomb && this.distance > 0 ){
context.font = "30px Arial";
context.fillStyle = "#000";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(this.distance,(this.x*this.w)+(this.w/2), (this.y*this.w) + (this.w/2) );
}
}
}
reval()
{
this.visible = true;
}
calculateProximity(grid)
{
let counter = 0;
for(let x = this.x-1; x <= this.x+1; ++x)
{
for(let y = this.y-1; y <= this.y+1; ++y)
{
if( x >= 0 && y >= 0 && x < grid.length && y < grid[0].length )
{
if( grid[x][y].bomb )
{
counter++;
}
}
}
}
this.distance = counter;
}
}