diff --git a/src/Board.java b/src/Board.java index 8ced168..47594cd 100644 --- a/src/Board.java +++ b/src/Board.java @@ -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) { diff --git a/src/Tile.java b/src/Tile.java index 3f0aa05..3e90b9f 100644 --- a/src/Tile.java +++ b/src/Tile.java @@ -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");