Support expanding an uncovered tile when the surrounding flagged tiles number is the same as the tile value.
This commit is contained in:
parent
8d1714777d
commit
2b63db9745
2 changed files with 18 additions and 0 deletions
|
|
@ -115,6 +115,21 @@ public class Board extends JPanel {
|
||||||
setVisible(true);
|
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() {
|
public void showMines() {
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
for (int i = 0; i < this.height; i += 1) {
|
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) {
|
if (SwingUtilities.isLeftMouseButton(e) && !this.uncovered && !this.flagged) {
|
||||||
this.setTileIcon("0");
|
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)) {
|
} else if (SwingUtilities.isMiddleMouseButton(e)) {
|
||||||
if (!this.flagged) {
|
if (!this.flagged) {
|
||||||
this.setTileIcon("0");
|
this.setTileIcon("0");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue