In the game of Minesweeper, a player searches for hidden bombs on a rectangular grid. The game board is represented by a grid of booleans marking bomb locations. A grid value is true if there is a bomb at that location, false otherwise. A user can click on any cell they choose. The game is lost when the user clicks on a cell containing a bomb. The game is won when all cells not containing bombs have been opened and the only remaining cells are those containing bombs.
Given such a grid of bomb locations, the method createCountGrid() constructs a new grid of integers storing the count of bombs in each neighborhood. The neighborhood for a location includes the location itself and its eight adjacent locations. In the returned grid, each value will be a number from 0 to 9.
If passed the boolean grid on the left, createCountGrid() returns the grid of int values on the right:
Here are the example grids: see image.
The examples below demonstrate how to compute the countGrid from the bombGrid.
A. In "Example A" one can see the cell [0][0] has a count of 1 because the only adjacent cell containing a bomb is [1][1].
B. In "Example B" one can see the cell [1][2] has a count of 0 because there are no adjacent cells containing a bomb.
C. In "Example C" one can see the cell [1][1] has a count of 4 because there are 4 adjacent cells containing a bomb. [0][0] , [0][2], [2][0], [2][1]
D. In "Example D" one can see the cell [1][1] has a count of 3 because there are 3 adjacent cells containing a bomb (including the cell itself). [1][1] , [2][0], [2][2]
Examples: see image.
1. Implement the Grid class shown below in the UML, so it can be tested via zyBook
2. Create a GUI using the java Swing package so that it behaves as follows.
1. Implement the overloaded constructors for the Grid class shown below in the UML
2. When a user clicks on a cell that has a 0 count reveal adjacent cells as follows:
CLASS Grid |
- bombGrid : boolean[][] - countGrid : int[][] - numRows : int - numColumns : int - numBombs : int |
+ Grid() : // 10rows, 10 columns, (10 x 10), 25 bombs + Grid(int rows, int columns): // (rows x columns Grid), default value of 25 bombs + Grid(int rows, int columns, int numBombs): // (rows x columns Grid), numBombs as specified + getNumRows(): int + getNumBombs(): int + getBombGrid(): boolean[][] + getCountGrid(): int[][] + isBombAtLocation(int row, int column): boolean + getCountAtLocation(int row, int column): int - createBombGrid(): void // called by constructors to create and populate the bombGrid - createCountGrid(): void // called by constructors to create and populate countGrid from bombGrid |