-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCell.java
More file actions
78 lines (57 loc) · 1.36 KB
/
Cell.java
File metadata and controls
78 lines (57 loc) · 1.36 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
public class Cell {
private int minedNeighbors;
private boolean isMine;
private boolean isVisible;
private boolean isFlagged;
private final static String HIDDEN = "H";
private final static String EMPTY = " ";
private final static String FLAGGED = "f";
private final static String MINED = "!";
public Cell () {
minedNeighbors = 0;
isMine = false;
isVisible = false;
isFlagged = false;
}
public int getMinedNeighbors () {
return minedNeighbors;
}
public void countLiveNeighbor () {
minedNeighbors = minedNeighbors + 1;
}
public boolean getMined () {
return isMine;
}
public void setMined () {
isMine = true;
}
public boolean getVisibility () {
return isVisible;
}
public void setVisible () {
isVisible = true;
}
public boolean getFlagged () {
return isFlagged;
}
public void toggleFlagged () {
isFlagged = !isFlagged;
}
public String toString () {
if (isVisible) {
if (isMine) {
return MINED;
} else if (minedNeighbors == 0) {
return EMPTY;
} else {
return Integer.toString(minedNeighbors);
}
} else {
if (isFlagged) {
return FLAGGED;
} else {
return HIDDEN;
}
}
}
} // class Cell