implementing the computer game minesweeper. The game of minesweeper works as fol
ID: 3692206 • Letter: I
Question
implementing the computer game minesweeper. The game of minesweeper works as follows:
There is a rectangular grid of tiles
Hidden under some of the tiles are mines
Your goal is to mark all the tiles that contain mines and uncover all the tiles that don't contain mines
If you uncover a tile that contains a mine you lose the game
If you uncover a tile that doesn't contain a mine, it tells you how many mines
are hidden in the eight surrounding squares
Here are some example boards with all of their contents revealed so that you can get an idea as to what they look like.
Example 1:
2* * 2 0 15 * 3 0 0* * 2 0
012 3
Example 2:
9 0 0 0 00 8 0 0 0 00 7 0 1 1 10 6 0 1 * 11 5 0 1 1 11 4 1 1 1 01 3 1 * 1 00 2 1 1 1 00 1 1 2 1 10 0 * 2 * 10
0 1 2 34
Requirements
Name your executable mine_sweeper.out
You must submit a makefile named Makefile, along with the necessary .c and .h
files needed to compile your program
1. You must have at least 2 .c files
Your program should accept the following command line arguments
1. The number of rows
The number of columns
The number of mines
Optionally a seed to the random number generator
1. If no seed is given then you should seed the random number generator with the current time
If not enough command line parameters are given your program should print a usage message and terminate.
You MUST USE A STRUCT to store your board state
1. This includes but is not limited to: the size of your board, the number of mines
on the board, and the status of each tile (revealed, concealed, marked, etc)
During each turn the user will be asked to select a row and column number to take an action on
You must validate that the tile they select is contained within the board
If the row and column are not valid, you should repeatedly ask the user for a new row and column until they enter a valid one.
After selecting a tile the user will be presented with a list of actions to take based
on the tile they selected
If the tile is concealed, they may reveal it, mark it as a mine, mark it as a possible mine, or cancel their move
If the tile is marked as a mine, they may remove their marker or cancel their move.
If the tile is marked as a possible mine, they may remove their marker or cancel their move
If the tile is already revealed tell the user that the tile is already revealed
If the user chooses to cancel their action or the tile is already revealed the user should be asked for a new tile and a new action to take on it
We will be using the following symbols in your board 1. #: a concealed tile
2. *: a mine
3. !: a tile marked as a mine
4. ?: a tile marked as potentially being a mine
Since mines will be randomly distributed around the board it is important that you follow the same algorithm for placing mines as I did. The algorithm is
For each mine that needs to be placed:
1. randomly choose a row
2. randomly choose a column
3. If the board at the row and column does not contain a mine place it there 4. else repeat beginning at sub-step 1
You should also print out where you place your mines so that you can confirm that they are being placed in the same locations as my program
9. Each tile that does not contain a mine, once revealed, shows the number of mines contained in the 8 tiles surrounding it
1. If the user reveals a concealed tile that has 0 mines surrounding it, then not only that tile but all concealed tiles that do not contain mines next to it should also be revealed
If a new tile is encountered that has 0 mines surrounding it, the process repeats
Hint, this involves recursion
10.The user losers if they reveal a mine
11.The user wins if they reveal all non-mine tiles and have marked all tiles that contain a mine
12.After the game is over the entire board should be revealed whether the user won or not should be displayed.
Example 1:
3 # # # ## 2 # # # ## 1 # # # ## 0 # # # ##
0 1 2 34
Enter row a row between 0-3 and a column between 0-4: 3 0 Enter Action
0. Reveal
1. Question
2. Mark
3. Cancel
Action: 0
There are 2 mines left 3 0 0 0 1#
2 0 0 0 1#
1 1 1 0 11
0 # 1 0 00
0 1 2 34
Enter row a row between 0-3 and a column between 0-4: 0 0 Enter Action
0. Reveal
1. Question
2. Mark
3. Cancel
Action: 2
There are 1 mines left
3 0 0 0 1#
2 0 0 0 1#
1 1 1 0 11
0 ! 1 0 00
0 1 2 34
Enter row a row between 0-3 and a column between 0-4: 2 4 Enter Action
0. Reveal
1. Question
2. Mark
3. Cancel
Action: 1
There are 1 mines left 3 0 0 0 1#
2 0 0 0 1?
1 1 1 0 11
0 ! 1 0 00 0 1 2 34
2. Mark
3. Cancel
Action: 0
There are 1 mines left 3 0 0 0 11
2 0 0 0 1?
1 1 1 0 11
0 ! 1 0 00
0 1 2 34
Enter row a row between 0-3 and a column between 0-4: 2 4 Enter Action
0. UnQuestion
1. Cancel
Action: 0
There are 1 mines left
3 0 0 0 11
2 0 0 0 1#
1 1 1 0 11
0 ! 1 0 00
0 1 2 34
Enter row a row between 0-3 and a column between 0-4: 0 0
Enter Action
0. UnMark
1. Cancel
Action: 0
There are 2 mines left 3 0 0 0 11
2 0 0 0 1# 1 1 1 0 11 0 # 1 0 00
0 1 2 34
Enter row a row between 0-3 and a column between 0-4: 0 0 Enter Action
0. Reveal
1. Question
2. Mark
3. Cancel
Action: 2
There are 1 mines left
3 0 0 0 11
2 0 0 0 1#
1 1 1 0 11
0 ! 1 0 00
0 1 2 34
Enter row a row between 0-3 and a column between 0-4: 1 1 This tile is already revealed.
Enter row a row between 0-3 and a column between 0-4: 0 2 This tile is already revealed.
Enter row a row between 0-3 and a column between 0-4: 2 99 Enter row a row between 0-3 and a column between 0-4: 2 4 Enter Action
0. Reveal
1. Question 2. Mark
3. Cancel Action: 0 3 0 0 0 11 2 0 0 0 1* 1 1 1 0 11 0 * 1 0 00
0 1 2 34 You Lost :(
Explanation / Answer
Hi below i have written a c++ sample code for your reference for Minesweeper game and hope it helps you :)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.