The Game Board Create a representation of the minesweeper as a char 2D Array. In
ID: 3532633 • Letter: T
Question
The Game Board
Create a representation of the minesweeper as a char 2D Array. Initialize it to some initial
state. To make it easier, first create a 5x5 board, and place 5 bombs wherever you would
like, then update the numbers that indicate neighboring bombs. Create a second
representation of the board that represents the revealed state of each cell (e.g. it has a 1-1
mapping to the first board that indicates whether a cell is in a revealed state) Write the
following methods, keeping in mind you will have to determine the appropriate
inputs/outputs (e.g. arguments/return types).
printBoard(): prints a Minesweeper board to screen in text form. Keep in mind, that the
printed board should reflect which cells have already been revealed.
revealCell(): appropriately modifies the state array when a cell is to be revealed
You should test both of these methods before moving on.
Now, write a main game loop that makes use of the two methods you just wrote. Your
game loop should interact with the user asking her for any inputs you had identified in
Milestone 1, and trivially, should be able to identify when the user has lost (e.g. hit a
mine). At this point, no cascading reveals are necessary
Explanation / Answer
#include // interger to pointer without cast PROBLEM.... #include // SOLUTION : whenever using string the data type // of the array must be char void welcome(); void rand_mines(char msweep[12][12]); void printmatrix(char msweep[12][12],int r,char user_chart[12][12]); int process(char msweep[12][12],int r,int c,char user_chart[12][12]); int main() { // size of array is 10,array starts from 1 to 11 char msweep[12][12] = {{'0'}}; int i,r,c; char user_chart[12][12] = {{'0'}}; // welcome(); rand_mines(msweep); // printmatrix(msweep,12,user_chart); // note grid from 1 to 11 printf("Enter your location(ONLY 1 - 11) on the minefield x,y "); scanf("%d%d",&r,&c); printmatrix(msweep,12,user_chart); i = process(msweep,r,c,user_chart); //returns 1 or 0,1 is notmine 0 = mine while(i == 1) { printf("Lucky BRAT, live on for another step "); printf(" %c Surrounding MINEs ",msweep[r][c]); printmatrix(msweep,12,user_chart); printf("enter next move...(ONLY 1 - 11) "); scanf("%d%d",&r,&c); i=0; i = process(msweep,r,c,user_chart); } if(i==0) printf("Game OVER, ta ta. you stepped on a MINE !! "); return 0; } void welcome() { char op; // opereation printf("Welcome to MINESWEEPER in C >>..... "); printf("EnterRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.