Question: I need help with my minesweeper program.I want this in c thx . The outline of the minesweeper. structure: two 2 - dimensional array:minemap and
I need help with my minesweeper program.I want this in c thx
The outline of the minesweeper.
structure:
two dimensional array:minemap and cellstatus
minemap is store where the mines are the neighboring
mine counts
cellstatus store the status of each cell during gameplay which is untouched opened and flagged.It will be update during the process
indicating it's a mine
indicating untouched
indicating opened
indicating flagged
the height and width of the game board is
# define H
# define W
# define MINE
# define UNTOUCHED
# define OPENED
# define FLAGGED
int mineMap HW;
int cellStatus HW;
int N;
No other global variable are allowed
#include
#include
only this two header file are allowed
Initializing Game Boards
The main function calls the initGameBoard function,place the mines in mineMap and set all the cells UNTOUCHED in cellStatus.
read the number of mines N and then the locations of the N mines one by one.
We use the MINE to mark these mine locations in the mineMap.
for Loop, read in N mine
for each mine,read in column and row
scanfc d&c&r;
getchar; get the pending new line
place the MINE in the mineMap
complete the printMineMap function to print the
mineMap We use numbers and to represent
the five rows, and capital letters A B C D and E to represent the five columns
A cell will display a to indicate there is no mine in it or display a to indicate
the presence of a mine in that cell.
Count the neighbouring mine
The main function invokes the fillMineNeighborhood function, which counts the number of nearby mines.For each empty not mine containing cell in mineM ap fillMineNeighborhood counts the total number of mines in the neighboring cells and stores the number in the mineMap array
Print gameboard
After each input,on the screen using the printGameBoard function.use the numbers to represent the five rows,
the letters A B C D E to represent the five columns.
there are three cell status, UNTOUCHED, OPENED, FLAGGED in cellStatus
For UNTOUCHED cells, display
For FLAGGED cells, display &
For OPENED cells, display the value in mineMap
Choose cell by player
In each round of the game, the main function displays the game board and prompts the player to enter the location of the selected cell.Initially, the game board is displayed with all cells UNTOUCHED, and the game waits for the user to select a cell.After the player inputs the location of a selected cell, we need to check the validation of the input.
If the cell is opened or flagged, we need to remind the
player and ask for the input again, until the input is appropriate.If the input location is invalid.we need to remind the player and ask for the input again, until the input is valid.
If the input is valid,let the player choose open the cell or flag the cell and update the cellStatus array accordingly.
If the player opened the cell and the cell is mine,the player loses the game The mineMap will be displayed to tell the player the correct result and a message to let the player know he lose.
If the opened cell is not a mine, consider the winning condition.If it is not fulfill the condition, update and next round.If the condition is fulfilled,print a message to player. The winning condition is to open all the nonmine cell
If the player choose to flag the cell,, the program will display the cell as flagged by the character & and then prompt for the next input.It is important to note that the flagged cell remains unopened; it is only marked as suspicious, but not opened yet.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
