QuestionQuestion

Problem Statement:
For this assignment, you will implement a game.

Minesweeper
This game was made popular by the Windows operating system in the early 1990s, and it has continued to be a pre-installed game until Windows 8.
The game is very simple. The object of the game is to open/reveal every cell on the board without detonating a mine. Every cell contains a number or a mine. The numbers tell you how many mines surround the cell in the horizontal, vertical, and diagonal directions, e.g. at most, 8 possible mines surrounding a cell. You can flag a cell, which helps you remember where you think there is a mine to not detonate. If you select to open/reveal a cell that has a mine, then you automatically lose the game!

You will then randomly distribute the mines on the board and setup the numbers describing how many adjacent mines to each cell. After that, you will display a blank board, and ask the user to flag or open a cell on the board until the user selects a cell that contains a mine (losing the game) or selects all cells free of mines (winning the game). After the user wins or loses, you will ask the user if he/she wants to play again. If so, you must get the number of rows, columns, and mines for the new game and create a new board for a new game. BTW, you can display row and column numbers on board to make it easier to read/know which row and column to select!!!

Example run of a game:

a.o ut –r 9 –c 9 –m 10

-------------------
| | | | | | | | | |
-------------------
| | | | | | | | | |
-------------------
| | | | | | | | | |
-------------------
| | | | | | | | | |

-------------------
| | | | | | | | | |
-------------------
| | | | | | | | | |
-------------------
| | | | | | | | | |
-------------------
| | | | | | | | | |
-------------------
| | | | | | | | | |
-------------------

Flag(1) or Open(2): 2 row, col: 0 4

You lose!!!
-------------------
|1|1|0|1|*|1|0|0|0|
-------------------
|*|2|1|2|2|2|0|0|0|
-------------------
|2|*|2|2|*|1|0|0|0|
-------------------
|1|1|3|*|3|1|0|0|0|
-------------------
|1|1|3|*|2|0|0|0|0|
-------------------
|1|*|3|2|2|0|0|0|0|
-------------------
|1|1|2|*|1|0|0|0|0|
-------------------
|1|2|3|2|1|0|0|0|0|
-------------------
|1|*|*|1|0|0|0|0|0|
-------------------

Do you want to play again (1-yes, 2-no): 1 How many rows, cols? 9 9
How many mines? 10
-------------------
| | | | | | | | | |
-------------------
| | | | | | | | | |
-------------------
| | | | | | | | | |
-------------------
| | | | | | | | | |
-------------------
| | | | | | | | | |
-------------------
| | | | | | | | | |
-------------------
| | | | | | | | | |
-------------------
| | | | | | | | | |
-------------------
| | | | | | | | | |
-------------------

Flag(1) or Open(2): 2 row, col: 0 0
-------------------
|1| | | | | | | | |

-------------------
| | | | | | | | | |
-------------------
| | | | | | | | | |
-------------------
| | | | | | | | | |
-------------------
| | | | | | | | | |
-------------------
| | | | | | | | | |
-------------------
| | | | | | | | | |
-------------------
| | | | | | | | | |
-------------------
| | | | | | | | | |
-------------------

Flag(1) or Open(2): 2 row, col: 8 0
-------------------
|1| | | | | | | | |
-------------------
| | | | | | | | | |
-------------------
| | | | | | | | | |
-------------------
| | | | | | | | | |
-------------------
| | | | | | | | | |
-------------------
| | | | | | | | | |
-------------------
| | | | | | | | | |
-------------------
| | | | | | | | | |
-------------------
|1| | | | | | | | |
-------------------

Flag(1) or Open(2): 2 row, col: 5 5
-------------------
|1| | | | |1|0|0|0|
-------------------
| | | | | |2|0|0|0|
-------------------
| | | | | |1|0|0|0|
-------------------
| | | | |3|1|0|0|0|
-------------------
| | | | |2|0|0|0|0|
-------------------
| | | | |2|0|0|0|0|
-------------------
| | | | |1|0|0|0|0|
-------------------
| | | |2|1|0|0|0|0|
-------------------
|1| | |1|0|0|0|0|0|
-------------------

Flag(1) or Open(2): 1

row, col: 6 3
-------------------
|1| | | | |1|0|0|0|
-------------------
| | | | | |2|0|0|0|
-------------------
| | | | | |1|0|0|0|
-------------------
| | | | |3|1|0|0|0|
-------------------
| | | | |2|0|0|0|0|
-------------------
| | | | |2|0|0|0|0|
-------------------
| | | |!|1|0|0|0|0|
-------------------
| | | |2|1|0|0|0|0|
-------------------
|1| | |1|0|0|0|0|0|
-------------------



Flag(1) or Open(2): 2 row, col: 7 1
-------------------
|1|1|0|1|!|1|0|0|0|
-------------------
|!|2|1|2|2|2|0|0|0|
-------------------
|2|!|2|2|!|1|0|0|0|
-------------------
|1|1|3|!|3|1|0|0|0|
-------------------
|1|1|3|!|2|0|0|0|0|
-------------------
|1|!|3|2|2|0|0|0|0|
-------------------
|1|1|2|!|1|0|0|0|0|
-------------------
|1|2| |2|1|0|0|0|0|
-------------------
|1|!|!|1|0|0|0|0|0|
-------------------

Flag(1) or Open(2): 2 row, col: 7 2 Congratulations!!!
-------------------
|1|1|0|1|*|1|0|0|0|
-------------------
|*|2|1|2|2|2|0|0|0|
-------------------
|2|*|2|2|*|1|0|0|0|
-------------------
|1|1|3|*|3|1|0|0|0|
-------------------
|1|1|3|*|2|0|0|0|0|
-------------------
|1|*|3|2|2|0|0|0|0|
-------------------
|1|1|2|*|1|0|0|0|0|
-------------------

|1|2|3|2|1|0|0|0|0|
-------------------
|1|*|*|1|0|0|0|0|0|
-------------------

Do you want to play again (1-yes, 2-no): 2

Requirements for game:
• You must provide a usage message, if the user enters incorrect command-line arguments, and they can come in any order!
• You must not have functions over 15-20 lines long (-10 automatically)
• You must not use global variables (-10 automatically)
• You must ask the user if he/she wants to play again
o If no, then end
o If yes, then prompt for rows, cols, and mines for new game.
• You must not have any memory leaks (-10 automatically)
• You must detect these errors:
o Invalid row or column to flag or open
o Opening a cell that has already been opened

Extra: Recursively open all cells adjacent to 0 cell
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.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define BOMB -1
#define FLAG_SIGN '!'
#define EMPTY ' '
#define OPEN 2
#define FLAG 1
#define CLOSE 0
#define DIED 0
#define ALIVE 1
#define YES 1
#define NO 2

struct Cell {
    int isOpen;
    int value;
    char show;
};

typedef struct Cell Cell;

// prototypes
/**
*
* @param board
* @param r board dimension
* @param c board dimension
* @param i chosen position
* @param j chosen position
* @return 1 if it's a bomb, otherwise return 0
*/
int isBomb(Cell ** board, int r, int c, int i, int j);

/**
* count number of bomb on its neighborhood
* @param board
* @param r board dimension
* @param c board dimension
* @param i chosen position
* @param j chosen position
* @return number of bomb on its neighborhood
*/
int getCellNumber(Cell ** board, int r, int c, int i, int j);

/**
* set up the board
* close all cells, hid all of them
* @param board
* @param r chosen position
* @param c chosen position
*/
void setEmptyBoard(Cell ** board, int r, int c);

/**
* put m bombs on the board at random position
* @param board
* @param r
* @param c
* @param m
*/
void putBombOnBoard(Cell ** board, int r, int c, int m);

/**
* set up the board
* put number to cell that doesn;t contain bomb
* @param board
* @param r chosen position
* @param c chosen position
*/
void setNumber(Cell ** board, int r, int c);

/**
* initialze the board
* @param r board dimension
* @param c board dimension
* @param m number of mine
* @return the board
*/
Cell ** getHiddenBoard(int r, int c, int m);

/**
* print the board to screen
* @param board
* @param r board dimension
* @param c board dimension
*/
void printBoard(Cell ** board, int r, int c);

/**
* count number of opened cell
* @param board
* @param r board dimension
* @param c board dimension
* @return number of opened cell
*/
int openCellNum(Cell ** board, int r, int c);...

By purchasing this solution you'll be able to access the following files:
Solution.c.

$60.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats