Conversation
This reverts commit ca74ea0.
| private final JButton[][] buttons = new JButton[HEIGHT][WIDTH]; | ||
| private final Random rng = new Random(); | ||
| private Optional<boolean[][]> mines = Optional.empty(); | ||
| private int numCellsRemaining; |
There was a problem hiding this comment.
This is the number of cells that do not have a mine and has not yet been opened. The name is not clear and can be misunderstood to mean the number of cells not yet opened, including cells with bombs. It is not clear what this field is used for. All we know is that it is decremented (line 106).
| * 2. The `numCellsRemaining` variable to the number of non-mine | ||
| * cells (`WIDTH` * `HEIGHT` - `NUM_MINES`). | ||
| * | ||
| * @param firstCellX X-index of first cell opened. This cannot be a mine. |
There was a problem hiding this comment.
I usually avoid x and y and use row and column (or row and col, or r and c). This avoids the confusion about whether rows corresponds to y or x.
| // - Decrement `numCellsRemaining` | ||
| // - If all cells are open, display "You Win" in a dialog box | ||
| // - Extra credit: If the number of neighboring cells is 0, | ||
| // automatically open all neighboring cells |
There was a problem hiding this comment.
Is there any way to flag a bomb? Should it be extra credit?
|
|
||
| final JPanel controlPanel = new JPanel(); | ||
| final JButton resetButton = new JButton("Reset"); | ||
| resetButton.addActionListener(null); // TODO replace null with method reference that resets the game |
There was a problem hiding this comment.
The TODO is actually part of the assignment.
| final MineSweeper mineSweeper = new MineSweeper(); | ||
| SwingUtilities.invokeLater(mineSweeper::createAndShowFrame); | ||
| } | ||
| } |
There was a problem hiding this comment.
Add tests so that the students can test their code as they progress. This gets them used to TDD and gives them a few carrots along the way.
This reverts commit ca74ea0.