Question
Program Overview: The game of Minesweeper (http://www.freeminesweeper.org/minecore.html) is traditionally a one-player game played against a computer. There are several covered squares and several of these
Program Overview:
The game of Minesweeper (http://www.freeminesweeper.org/minecore.html) is traditionally a one-player game played against a computer. There are several covered squares and several of these squares have mines in them. The goal of the game is to label all the mines without stepping on any.
The computer hides the mines in the minefield. The user does not know where the mines are. The user then selects squares in the minefield. If the square contains a mine, the game is over. If the square does not contain a mine, the computer puts a number on the square that indicates how many mines are immediate neighbors to that square (or leaves the square blank if there are no immediate neighbors)..
You will create a function that provides the user with all 4 selections (described below). If you only implement the basic requirements (the first 2) you should still include the remaining selections on the menu. If the user chooses 3 or 4 and you chose not to implement that selections, you should print a message stating you did not implement this feature. You can title your game whatever you wish. Below is an example of a basic menu. You may be as creative as you wish with the menu or just use this basic format.
Below is a description of each menu selection.
Selection 1 - Basic
Read in the board information from a file. The first line of the file will contain two integers to tell you how big the board is (first height (row), then width(col)). The dimensions will not exceed 20 x 20. However, the dimensions could be something like 20 X 10. The remaining lines in the file will contain the minefield, where 0 means there is no mine and 1 means there is a mine. Your goal is to make the computer print out the completely revealed board for that minefield, where X indicates the presence of a mine, and the remaining squares contain a count of how many mines are in its immediately neighboring cells.
Example:
Selection 2 Randomly generate the board
You will use command line arguments to provide the file name to be read in. I will provide a sample input file for you to use to test your program. Your output should be printed to a file provided through command line arguments.
Randomly generate the input file rather than reading in the information from a file. You will need to ask the user for the height (rows) and width (col) of the board. The minimal row/col should be 5 and maximum should be 20. The number of mines to be randomly place on this board will be 15% of the size of the board. In other words, height*width*.15. Make sure you do not allow to place multiple mines in one place on the board. To complete this selection, you will need to look up the rand and srand functions. The URLs listed below are examples of how to randomly generate information.
After you have generated the file then create the solution and print it to the output file provide on the command line.
Example:
Enter the Height and Width you wish the board to be!
The Height and Width should be between 5 - 20
You must place a space between the height and width.
Selection 3 - Basic playable
In addition to completing the requirements for Selection 2, you will need to provide code allowing the game to be playable in a basic form. As an example, after the game board has been randomly generated and the solution created, you should generate a playable board using ., as shown below. The example below is for a 10 by 10 board. While it is not required, feel free to add a row of numbers across the top and left side of the board to denote the rows and columns. This will make it easier for the user to determine the row/col input.
Ask the user to enter the location they want to uncover by entering the row and column.
If the row - column is an X then declare that the user has hit a mine and end the game. If the guess is not an X then replace the . with the value and continue, as shown.
Example:
If the user is able to uncover all spaces without hitting a mine, print a congratulatory message.
Selection 4
In addition to completing Selection 2 you will need to provide an selection making the game playable in the fashion of the original minesweeper game. As an example:
Again, while it is not required, feel free to add a row of numbers across the top and left side of the board to denote the rows and columns. This will make it easier for the user to determine the row/col input.
In the above example, the user chose row 0 and column 0. This selection basically looks for a 0 and any of its neighbors that are not a mine. Using recursion, it continues looking for 0s revealing all non-mine neighboring values.
Other Programming Requirements
You must have a minimal of 4 files.
main.c this file should contain only the main. The main should have a minimal amount of code. If you have an algorithm (a set of steps necessary to complete a task) that is more than a couple lines of code (excluding loops) you should create a function for this routine.
functions.c this file contains the implementation of the functions used with this assignment
functions.h this file contains the prototypes for the functions used in this program. You should use #ifndef and #endif in this file. (see Include Guards explanation below.)
README this is a plaintext file. This file should be all caps and it does not need an extention. You should use this file to:
You must use file pointers to open the input and output files. These files will be determined using command line arguments.
You must use 2 dimensional (2D) arrays.
You must dynamically allocate memory for all 2D arrays.
When necessary, you must validate user data.
As stated above you must use a menu to determine the selection the user wishes to run.
10 10 0 0 0 00 0 0 0 1 0 0 1 0 0 0 0 0 0 1 0 1 11 0 0 0 0 2 X 2 1 x 1 0 0 0 0 2 X 2 1 1112 2 1 1 11 0001x 2000 0 0 0 0 11 0 0 0 0 0 0 0 00 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 x 1 011 1 0 0 0 1 11 0 0 0 11 1 0 0 0 0 0 0 0 2 X 2 0 0 0 111 0 2 X 2 0 0 0 1 X 1 0 11 1 0 0 0 0 00 0 0 1 0 0 0 0 0 00 0 0 1 0 0 00 0 1 00 0 0 0 0Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started