Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Minesweeper is a two dimensional grid that has mines hidden randomly throughout the game space. The player guesses a cell in the grid. If
Minesweeper is a two dimensional grid that has mines hidden randomly throughout the game space. The player guesses a cell in the grid. If the cell has a mine in it the mine goes off and the game is over. If the cell does not have a mine in it the game will reveal all of the adjacent blank cells. If any of the cells have mines adjacent to them then a number is placed in that cell that indicates how many mines are adjacent. Once all the blank cells and cells with numbers have been revealed the player is given the opportunity to guess at another cell. Once all of the non-mine cells have been revealed the player wins. Our game will have ten (10) cells with mines in it. The initial filling of the grid will be done with a random generator to detemine the location of the cells with mines. The game will ask the player for a height and width to create the minefield two dimensional grid. For this assignment we will use three classes, the main minesweeper class, a game class and a grid class. The minesweeper class will have the main method in it and will create a new game object and call the start method out of the game object. 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. displayGridData0: 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. There are some sample screenshots in a following section. Screen Shots These screen shots are examples of what your application should look like. run: Enter the height of the grid: 10 Enter the width of the grid: 10 There are a total of 10 mines in the mine field. 12345 6789 10 ****** **** ********** ***** ***** 3. **** *** 4 * * 6. ***** ***** 7 ******** 8. ***** ** 10 Pick a spot to check for a mine. First enter the row number then the column number: 10 10 There are a total of 10 mines in the mine field. 1234 5 6789 10 ********** 1 2 ** 42222222
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Answer MineSweeperjava package minesweeper public class MineSweeper public static void mainString args create game object Game g new Game start the ga...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