-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTile.java
51 lines (47 loc) · 1.3 KB
/
Tile.java
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
public class Tile {
/** the current state of the Tile */
public TileState tileState;
/** whether the given tile is a bomb */
public boolean isBomb;
/** number of bomb neighbors */
public int numNeighbors;
/**
* Creates a new Tile with default state (covered, not a bomb, and zero bomb neighbors)
*/
public Tile() {
this.tileState = TileState.COVERED;
this.isBomb = false;
this.numNeighbors = 0;
}
/**
* Gets the string representation of the Tile.
* <ul>
* <li> if covered, "X"
* <li> if flagged, "F"
* <li> if uncovered,
* <ul>
* <li> if bomb, "B"
* <li> if not bomb, the number of bomb neighbors
* </ul>
* </ul>
* @return
*/
public String getRepresentation() {
if (this.tileState == null) {
throw new IllegalStateException("TileState is null");
}
switch (this.tileState) {
case COVERED:
return "X";
case FLAGGED:
return "F";
case UNCOVERED:
if (this.isBomb)
return "B";
else
return Integer.toString(numNeighbors);
default:
return "Z"; // compliation problem fixer
}
}
}