Question: Question : In this Program you will develop a simple version of the game MineSweeper using 2D arrays and functions. MineSweeper is a single-player puzzle

Question: In this Program you will develop a simple version of the game MineSweeper using 2D arrays and functions. MineSweeper is a single-player puzzle game. In this game, the user has to clear a board which contains hidden mines without exploding any of them. Each cell of the rectangular board either contains a mine or a number indicating number of mines in its eight neighboring cells. For details see https://en.wikipedia.org/wiki/Microsoft_Minesweeper. Your version of the game will look somewhat like this: You will display the board and ask the user to indicate the cell he wish to open. A cell on the board can either contain a mine or a number between 0 to 8 to indicate the number of mines adjacent to the cell. The number of mine in the board should be between 10- 15 and placed randomly on the board. Use rand () function to decide the number of mine and the cells where mines will be placed. The game is won once all blank squares have been uncovered without hitting a mine. The game is lost if user open a cell with a mine. You will need two 2D array of size 10x10, one for the game board and the other to keep track of the cells, which cell is hidden, and which is revealed to user. Your code should contain the following functions: 1. Setup_Board- to setup the board. This function will perform two tasks a. It will use rand () function to randomly decide the number of mine and the cells where mines will be placed. Create a function Place_Mines for this task. b. For all the cells without a mine, you will calculate the number of mines in their neighboring cells. Think of an efficient way to do this. Create a function Count_Neighboring_Mines for this task. You will call functions Place_Mines and Count_Neighboring_Mines in the function Setup_Board. 2. Display_Board- to display the board on the screen. Before printing the board, you can clear the screen and display the new board at the same location. Use system("CLS") to clear the screen, for this you will have to include standard library header file .

3. Play_Game - to implement the game logic. It will ask the user which cell to open or Flag. If user opens a cell having a bomb then game ends. If user opens a cell having a number greater then 0, then your game will simply reveal its content. However, if user opens a cell having no neighboring mines (in any of the surrounding eight cells) then all the neighboring eight cells are automatically revealed to the user. Your program should allow the user to Flag the cell he thinks contains bomb. You can use a 2D array to keep track of cells that are revealed to the user. Carefully think about the input parameters and return type of the functions. Your function should be short and precise. You can make your game colorful by using the C++ library . You can use the function given below to print a string at particular location on the screen //this function prints a string str at position (x,y) of the screen void PrintXY(int x, int y, char str[]){ COORD c; c.X = x; c.Y = y; SetConsoleCursorPosition(GetStdHandle( STD_OUTPUT_HANDLE), c); cout << str; cout.flush(); } You can use the function given below to print a string at a particular location on the screen using a specified color //this overloaded function prints a string str in specified color at pos(x,y) void PrintXY( int x, int y, char str[], int color) { COORD c; c.X = x; c.Y = y; HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_SCREEN_BUFFER_INFO info; GetConsoleScreenBufferInfo(h, &info); short ret = info.wAttributes; SetConsoleCursorPosition(h, c); SetConsoleTextAttribute(h, color); cout << str; cout.flush(); SetConsoleTextAttribute(h, ret); } Just copy-paste these function in your code and call them when needed.

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!