Question: Ineed help with following c++ program: write a simple text-based minesweeper program. For simplicity, assume that it is a 6x6 grid and there are four
Ineed help with following c++ program:
write a simple text-based minesweeper program. For simplicity, assume that it is a 6x6 grid and there are four mine tiles. In a true minesweeper game, the mine tiles are randomly initialized. But, here you will be reading the tile contents from a file mines.txt. Two sample executions are provided. To keep track of the game states, declare a 2D array of integers. Initially all cells will be set to -1 (meaning the tile has not been revealed), except for the cells representing the mines which will be set to -2. As the game progresses, each cell will represent the number of neighboring mines. Note that only safe tiles will be revealed. The program will use at least the following three functions. The load function will be used to read the grid content into the 2D array. This function will receive the grid and the filename. The recursive play function will be responsible for exploring and revealing the safe tiles starting from a given location. This function will receive the grid and the location (row and column). You will need to have a base case to check for boundary conditions. Finally, the print function will be used for displaying grid. It should only display the safe tiles that have been revealed. The mine tiles will be displayed only when the player selects a mine location. Write all your code in prog6.cpp. Declare constants for the size of the grid. Inside main, create a 2D array of integers. Then call the load function to read the grid contents. Use a loop to repeatedly display the grid with the safe tiles revealed, prompt the player for a tile location, and call the play function to reveal the locations of safe tiles. This loop should continue until either a mine tile has been selected or all safe tiles have been revealed. Your program should have error checking for proper command line argument and file open error.
this is how mines.txt looks like:
-----x x----- ---x-- ------ -x---- ------
Sample Execution 1: ------ ------ ------ ------ ------ ------ Enter tile location: 0 7 ------ ------ ------ ------ ------ ------ Enter tile location: 0 0 1----- ------ ------ ------ ------ ------ Enter tile location: 0 0 1----- ------ ------ ------ ------ ------ Enter tile location: 5 0 1----- ------ ------ ------ ------ 1----- Enter tile location: 5 5 1----- ----21 ----10 --2110 --1000 1-1000 Enter tile location: 0 1 11---- ----21 ----10 --2110 --1000 1-1000 Notice that there will not be any change. Notice that there will not be any change. Enter tile location: 0 2 11001- -11121 ----10 --2110 --1000 1-1000 Enter tile location: 2 0 11001- -11121 1---10 --2110 --1000 1-1000 Enter tile location: 2 1 11001- -11121 11--10 --2110 --1000 1-1000 Enter tile location: 2 2 11001- -11121 111-10 --2110 --1000 1-1000 Enter tile location: 3 0 11001- -11121 111-10 1-2110 --1000 1-1000 Enter tile location: 3 1 11001- -11121 111-10 112110 --1000 1-1000 Enter tile location: 4 0 11001- -11121 111-10 112110 1-1000 1-1000 Enter tile location: 5 1 11001x x11121 111x10 112110 1x1000 111000 Congrats! $ ./prog6 mines.txt ------ ------ ------ ------ ------ ------ Enter tile location: 0 0 1----- ------ ------ ------ ------ ------ Enter tile location: 5 5 1----- ----21 ----10 --2110 --1000 --1000 Enter tile location: 0 5 1----x x---21 ---x10 --2110 -x1000 --1000 Better luck next time!
P.S.:
For the non mine numbers, count number of mines 1 space away, then change this space's number from -1 to the resulting count'. have a separate if case for if the amount is zero and call a 'reveal the clear area' function.Guessing that the base zero is that mine is -2 and nonmine is -1.Have negative numbers display as '-' or something until a win condition is met.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
