-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRegularCell.pde
55 lines (48 loc) · 1.06 KB
/
RegularCell.pde
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
public class RegularCell extends Cell {
boolean uncovered;
RegularCell(int _col, int _row) {
super(_col, _row);
uncovered = false;
fillColor=color(180);
}
@Override
void uncover() {
uncovered =true;
fillColor = color(100);
//0s patch
if (cantTouchingBombs() == 0) {
for (Cell myCell : this.surroundingCells(cells)) {
if (!myCell.isUncovered())myCell.uncover();
}
}
}
@Override
boolean isUncovered() {
return uncovered;
}
@Override
boolean isBomb() {
return false;
}
@Override
void show() {
super.show();
if (uncovered) showNumber(cantTouchingBombs());
}
void showNumber(int n) {
if (n>0) {
textSize(size-10);
float m = map(n, 0, 8, 0, 255);
fill(m, 50, m/2);
textAlign(CENTER, CENTER);
text(Integer.toString(n), posX(), posY(), size, size);
}
}
int cantTouchingBombs() {
int countBombs = 0;
for (Cell myCell : surroundingCells(cells)) {
if (myCell instanceof Bomb) countBombs++;
}
return countBombs;
}
}