Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ that produces a two-dimensional board of bombs and numbers that could be used as a data structure inside a minesweeper game such as the

C++ that produces a two-dimensional board of bombs and numbers that could be used as a data structure inside a minesweeper game such as the one that comes with Microsoft Windows.

The display of the board shall be text-based and appear in the format shown in the example-program-output.txt file with each digit or character printed in a field width of three. A blank square shall appear as an underscore character, a bomb square shall appear as a '#' character, and a number square shall appear as the number.

The game board data structure shall consist of a two-dimensional integer array. A blank square shall be stored as a zero, a bomb shall be stored as a -1, and a number (i.e., clue) square shall be stored as the respective number.

The program shall follow this basic algorithm:

Create a game board as a two-dimensional integer array with MAX_ROWS and MAX_COLUMNS

Randomly fill the squares on the game board with bombs or zeros

Go through the board, square by square, looking for each bomb. When one is found, increment (by one) the values in the number squares surrounding a bomb

Display the game board on the screen

The program shall have no interaction with a user except for starting the program.

Software Design

To satisfy the software requirements, implement the design described below.

int main(void)

This function definition is finished. Make no changes to it. It contains an implementation of the basic algorithm described in the software requirements.

void fillTheGameBoard(int board[MAX_ROWS][MAX_COLUMNS])

Set up a double for loop that will iterate through each row and column of the board in order to fill the squares. Be sure to use the MAX_ROWS and MAX_COLUMNS constants in your 'for loop' source code instead of the literal numbers given for the those constants in the skeleton file. Inside the innermost 'for' loop, store a BOMB_DIGIT in a square when the following probability formula is true: (rand() % (MAX_ROWS - 3) == 0), otherwise, put an EMPTY_SQUARE_DIGIT in the square. Be sure to use the BOMB_DIGIT and EMPTY_SQUARE_DIGIT constants in your source code.

void displayTheGameBoard(int board[MAX_ROWS][MAX_COLUMNS])

Set up a double for loop that will iterate through each row and column of the board in order to print (in a width of 3) the contents of each square as shown in the example-program-output.txt file. Inside the inner for loop, use an if-else structure to do the following. If a square contains the BOMB_DIGIT, then print the BOMB_SYMBOL. If, instead, a square contains the EMPTY_SQUARE_DIGIT then, print the EMPTY_SQUARE_SYMBOL; otherwise, print the numeric value stored in the square.

void insertTheMineClues(int board[MAX_ROWS][MAX_COLUMNS])

This function works in conjunction with the incrementTheNeighborSquares function to put the mine number clues onto the board. To modularize the implementation, this function handles the part of finding each bomb on the board. The other function handles the part about correctly storing the number clues. Set up a double for loop that will iterate through each row and column of the board. Do the following inside the inner for loop. If a square contains the BOMB_DIGIT then call the incrementTheNeighborSquares function and pass it the board, the current row value, and the current column value.

void incrementTheNeighborSquares(int board[MAX_ROWS][MAX_COLUMNS], int bombRow, int bombColumn)

The algorithm checks all of the neighbor (i.e., adjacent) squares surrounding a bomb square. If a neighbor square does not contain the BOMB_DIGIT, then the value in the square is incremented by one. A double for loop is used to iterate through the row and column location of each neighbor square surrounding the bomb square. Because C++ does no range checking when an array is indexed, the algorithm checks that, also. This function definition is already finished. Make no changes to it.

Example output

image text in transcribed

Skeleton

image text in transcribed

--12#22#1 #3#211 2##1 2#4311 12#2#1 133422 1##3#1 13#32212#2 1111#12#2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Repairing And Querying Databases Under Aggregate Constraints

Authors: Sergio Flesca ,Filippo Furfaro ,Francesco Parisi

2011th Edition

146141640X, 978-1461416401

More Books

Students also viewed these Databases questions

Question

What do you mean by underwriting of shares ?

Answered: 1 week ago

Question

Define "Rights Issue".

Answered: 1 week ago

Question

Discuss the Rights issue procedure in detail.

Answered: 1 week ago

Question

Discuss the Rights issue procedure in detail.

Answered: 1 week ago

Question

Explain the procedure for valuation of shares.

Answered: 1 week ago