-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTile.java
More file actions
75 lines (66 loc) · 1.73 KB
/
Copy pathTile.java
File metadata and controls
75 lines (66 loc) · 1.73 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
public class Tile {
private final int CLOSED = 0;
private final int FLAGGED = 1;
private final int OPEN = 2;
// the state of a tile
private int state = CLOSED;
final private boolean hasMine;
private int nearMines;
public Tile(boolean hasMine){
this.hasMine = hasMine;
nearMines = 0;
}
/**
* @return true if a given tile is flagged, false if it is not
*/
public boolean isFlagged () {
return state == FLAGGED;
}
/**
* @return true if the tile has been opened otherwise false
*/
public boolean isOpen () {
return state == OPEN;
}
/**
* @return true if a tile has not been opened otherwise false
*/
public boolean isClosed () {
return state == CLOSED;
}
/**
* @return true if a tile is a mine false if it is not a mine
*/
public boolean isMine () {
return hasMine;
}
/**
* @return the amount of mines, as an int, surrounding the tile in a 1 tile radius
*/
public int getNearMines () {
return nearMines;
}
/**
* as the name implies this toggles if the tile is flagged
*/
public void toggleFlag () {
if(state == FLAGGED)
state = CLOSED;
else if(state == CLOSED)
state = FLAGGED;
}
/**
* sets the amount of mines near the tile
* @param mines the mines surrounding the tile in a 1 tile radius
*/
public void setNearMines (int mines) {
nearMines = mines;
}
/**
* opens the tile
*/
public void open () {
if(state != FLAGGED && state == CLOSED)
state = OPEN;
}
}