Question: This is a c++ program. 1:In need of some help with the flagging part of the program. If the user selects a cell that has

This is a c++ program.

1:In need of some help with the flagging part of the program. If the user selects a cell that has no mines surrounding it, then you will help the user by recursively opening all adjacent cells to empty cells, until you reach cells with a surround mine.

#include

#include

#include

using namespace std;

bool lost;

void drawMS(char minesweepergame[10][10],int mrow,int mcol,bool lost)

{

cout << " _";

for (int myR = 0; myR < mrow; myR++)

{

cout << myR << "_";

}

cout << endl;

for (int myC = 0; myC < mcol; myC++)

{

cout << myC << "|";

for (int myR = 0; myR < mrow; myR++)

{

if (minesweepergame[myR][myC]=='*' && lost)

{

cout << "!|";

}

if (minesweepergame[myR][myC]=='*')

{

cout << " |";

}

else if (minesweepergame[myR][myC]!=' ')

{

cout << "x|";

}

else

{

cout << "_|";

}

}

cout << endl;

}

}

int main()

{

lost = false;

int myX = 0;

int myY = 0;

char minesweepergame[10][10];

int mrow,mcol;

int bombs;

char selection;

do

{

lost = false;

cout<<" Give row, column and number of bombs:";

cin>>mrow>>mcol>>bombs;

for (int k1 = 0; k1

{

for(int k2=0;k2

{

minesweepergame[k1][k2]=' ';

}

}

for (int i = 0; i

{

int xpos = rand() % mrow;

int ypos = rand() % mcol;

if (minesweepergame[xpos][ypos]!='*')

{

minesweepergame[xpos][ypos] = '*';

}

else

{

i--;

}

}

drawMS(minesweepergame,mrow,mcol,lost);

cout << endl;

while (lost != true)

{

cout << "Input row 2 check." << endl;

cin >> myX;

cout << endl << "Input column 2 check." << endl;

cin >> myY;

if(myX>mrow-1 || myY>mcol-1)

{

cout << "Invalid row or column number";

continue;

}

if (minesweepergame[myX][myY]== 'x')

{

cout << "Invalid choice! Already opened";

continue;

}

if (minesweepergame[myX][myY]== '*')

{

cout << "Boom! Lost!";

lost = true;

}

else

{

cout << "Go Ahead!!!" << endl;

}

minesweepergame[myX][myY]= 'x';

cout << endl;

drawMS(minesweepergame,mrow,mcol,lost);

cout << endl;

}

cout<<"Enter 'y' to play again!!!";

cin>>selection;

}

while(selection == 'y');

system("pause");

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!