Question
How do I set up a Minesweeper game in Java? The game class will have the following methods: void start(): This method will be the
How do I set up a Minesweeper game in Java?
The game class will have the following methods:
void start(): This method will be the starting point of the game. It will need to ask the user to input the height and width of the grid, initialize the grid using the height and width, and call the gameLoop
void gameLoop(): This method will be the main loop that runs the game. This method will ask the user to input the cell that they want to check and will call the checkLocation method passing the cell location that the user just inserted.
int numberOfMines(int row, int col): This method will count the number of mines that are adjacent to the cell that is at the location given by the row and col values passed to it.
boolean checkLocation(int row, int col): This method will check if the location that is given by the row and col value has a mine. If it does not then it will call the clearBlanks method giving the current location.
void clearBlanks(int row, int col): This method will reveal all of the cells that are adjacent to the cell at the location given by the row and col values. If one of the adjacent cells has a mine adjacent to it, then a number will be put in that cells location that corresponds to the number of mines that are adjacent. If one of the adjacent cells does not have any mines adjacent to it, then that cell will be turned into a blank and the cells around it will be revealed and checked for mines. This process will continue until the only cells left all have numbers indicating the number of mines.
The grid class will have a constructor that takes two parameters, a height and a width. It will also have the following methods:
randomFillGrid(): This method will randomly place mines in the grid.
displayGrid(): This method will display the grid with the hidden and revealed cells.
displayGridData(): This method will display the grid with the locations of the mines revealed.
The previous list of methods is a minimum requirement. You can have more methods than these. However, these methods must appear and be used in your project.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started