forked from MichaelH13/CSIS321MineSweeper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTile.java
More file actions
96 lines (85 loc) · 1.95 KB
/
Tile.java
File metadata and controls
96 lines (85 loc) · 1.95 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import Game;
/**
* @author Keiko
*
* Class for representing a Minesweeper Tile.
*/
public class Tile
{
/**
* Constructor for Tile class
*
* @param yRow The tile's row
* @param xColumn The tile's column
* @param isBomb True of the tile is a bomb
*/
public Tile(int yRow, int xColumn, boolean isBomb)
{
_y = yRow;
_x = xColumn;
_isBomb = isBomb;
// Tile should start out not revealed
_isRevealed = false;
}
/**
* A method to determine if a tile has been revealed
*
* @return True if the tile is revealed
*/
public boolean isRevealed()
{
return _isRevealed;
}
/**
* A method to determine if the tile is a bomb
*
* @return True if the tile is a bomb
*/
public boolean isBomb()
{
return _isBomb;
}
/**
* A method to get the x coordinate of the tile
*
* @return The tile's x coordinate
*/
public int getX()
{
return _x;
}
/**
* A method to get the y coordinate of the tile
*
* @return The tile's y coordinate
*/
public int getY()
{
return _y;
}
/**
* A method to get the string representation of the Tile
*
* @return The Tile turned into a string
*/
public String toString()
{
// Get the neighbors of the Tile
Tile[] neighbors = Game.getField().getNeighbors(this);
// Count the number of neighbors that are bombs
int volatileNeighbors = 0;
for (Tile neighbor : neighbors)
{
if (neighbor.isBomb())
{
volatileNeighbors++;
}
}
// Return the string representation of the tile
return (" " + volatileNeighbors + " |");
}
private boolean _isBomb;
private boolean _isRevealed;
private int _x;
private int _y;
}