Support expanding a uncovered tile surrounded by unflagged tiles.
This commit is contained in:
parent
8d1714777d
commit
25f99b9447
2 changed files with 18 additions and 0 deletions
|
|
@ -115,6 +115,21 @@ public class Board extends JPanel {
|
|||
setVisible(true);
|
||||
}
|
||||
|
||||
public int getTileFlaggedNum(int row, int col) {
|
||||
int counter = 0;
|
||||
for (int i = row - 1; i <= row + 1; i += 1) {
|
||||
for (int j = col - 1; j <= col + 1; j += 1) {
|
||||
if (!(i < 0 || j < 0 || i >= this.height || j >= this.width) && !(i == row && j == col)) {
|
||||
Tile tile = this.tiles[i][j];
|
||||
if (tile.isFlagged()) {
|
||||
counter += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return counter;
|
||||
}
|
||||
|
||||
public void showMines() {
|
||||
setVisible(false);
|
||||
for (int i = 0; i < this.height; i += 1) {
|
||||
|
|
|
|||
|
|
@ -169,6 +169,9 @@ public class Tile extends JLabel implements MouseListener {
|
|||
}
|
||||
if (SwingUtilities.isLeftMouseButton(e) && !this.uncovered && !this.flagged) {
|
||||
this.setTileIcon("0");
|
||||
} else if (this.isUncovered() && e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(e) &&
|
||||
this.getValue() == this.board.getTileFlaggedNum(row, col)) {
|
||||
this.board.expand(row, col);
|
||||
} else if (SwingUtilities.isMiddleMouseButton(e)) {
|
||||
if (!this.flagged) {
|
||||
this.setTileIcon("0");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue