Ask C/C++ Expert


Home >> C/C++

Introduction

Minesweeper is a classic game that is installed with Microsoft Windows for more than two decades. The goal of the game is to discover all the mines hidden in a rectangular field.

In this project, you are required to write a Windows Console Application that implements most features of the minesweeper game.

The project is divided into two separate programs.

1. Map generator. A map generator produces an output file namely "map.txt". It is the game map of the minesweeper game.

2. Minesweeper game. This program reads "map.txt" and starts the game.

Program Design of "Map Generator"

The map generator generates a rectangle matrix of 9 rows and 10 columns, and each cell of the matrix contains an integer 0 or 1 only. Such a matrix represents the map of the minesweeper game.

File generation

The map generator should produce a text file contains 0 and 1 only, as shown above.

• The output file must be named "map.txt".

• The content of "map.txt" is a 9 rows by 10 columns matrix containing integers: 0 or 1.
• There is a space after each integer.
• It represents the map of the minesweeper game:
o If the cell at i-­-row and j-­-column is 0, then the cell (i, j) is an empty cell.
o If the cell at i-­-row and j-­-column is 1, then the cell (i, j) contains a bomb.
• The locations of the bombs are generated using the pseudo-­-random number generator.

We provide you a pseudo-­-code in producing the file. You must follow this pseudo-­-code when you submit your work.


#include int main(void) {
/* Declare all necessary variables here. */

/* Step 1: Read two integers "seed" and "n". */

/* Step 2: Initialize the random number generator by "seed". */

/* Step 3: Use nested for loop to initialize all elements in "matrix" to zero */

/* Step 4: Initialize "count" to zero. */

/* Step 5: Assign "n" 1's to "matrix" by the following algorithm: While "count" is less than "n"
Generate a random number between 0 and 8 and assign it to "row" Generate a random number between 0 and 9 and assign it to "column" If the element located at "row" and "column" in "matrix" is not 1
Assign 1 to this element Increase "count" by 1
End If End While

/* Step 6: Use nested for loop to print "matrix" onto "map.txt". */ return 0;
}

Program Design of "Minesweeper Game"

The "minesweeper game" program contains the proper game flow of the whole game. Figure 1 shows the high-­-level program design:

• Rectangle. Every rectangle represents a task in your project code. A task is a set of C statements that (1) updates the variables in your programs, (2) reads input from the user, or (3) prints output.

• Rhombus. Every rhombus represents a condition in your project code. A condition is expected to return a true value or a false value, with 0 representing false and 1 representing true.

In the following, we describe the design of important functions and conditions in the game..

Function: Read and Process Map

This task contains four sub-­-tasks:

1. Sub-­-task #1: Initialize a "real map" and a "display map". The game should keep two maps:
a. The "display map" is for display only.
b. The "real map" stores the location of bombs.

Your program should keep two integer 2D-­-arrays of 9 rows x 10 columns to represent the display map and the real map, respectively.

• The initial status of every cell in the display map should be initialized to the "hidden cell".
• The initial status of the real map is read from "map.txt".

2. Sub-­-task #2: read from "map.txt". The "map.txt" contains a 9 rows x 10 columns integer matrix. You are recommended to initialize the real map in the following way:

• Denote the real map as the variable "int real_map[9][10];"
• Denote the cell at i-­-th row and j-­-th column in "map.txt" as (i, j).
• If the (i, j) cell is 0, initialize the "real map": real_map[i-­-1][j-­-1] = '.';
• If the (i, j) cell is 1, initialize the "real map": real_map[i-­-1][j-­-1] = '*';

3. Sub-­-task #3: count the number of bombs. Though the "map.txt" always contains a matrix of 9 rows x 10 columns, the locations and the number of the bombs vary.

Your program should count the number of bombs inside "map.txt". Note that:
• The minimum number of bombs is 1.
• The maximum number of bombs is 90.

4. Sub-­-task #4: calculate the number of neighboring bombs. The original minesweeper puzzle provides hints to the player if an empty cell is surrounded by at least one bomb.

Such a hint is a number, indicating the number of bombs surrounding the empty cell. Let us call such a number the hint number. The following figure illustrates what the hint number means:

Your program should compute the hint numbers after the program has finished reading "map.txt", and then store the hint numbers onto the "real map".

Function: Display User Interface

This task contains three sub-­-tasks:

1. Sub-­-task #1: print the "display map". The user interface should show the current status of the "display map" to screen. You must print the "display map" using the following set of characters.

Characters stored in display map

Meaning

1-­-8

A hint number.

Space character

A revealed empty cell.

. (a dot)

A hidden cell.

* (asterisk)

A bomb (and it is printed when the game is over)

F

Flagged cell (will be mentioned later)

Also, you have to print the row numbers as well as the column numbers. You can find an example later.

2. Sub-­-task #2: Show the number of remaining flags. A flagged cell means a cell where the user thinks the bomb is hidden. This is only stored in the display map, not in the real map.3. Sub-­-task #3: Show the prompt for user input. A prompt is a message that tells the user to fill in input(s).

The prompt of the minesweeper program is the following string:
"1. Reveal / 2. Flag / 3. Un-­-Flag / 4. Quit [1-­-4]? "

Altogether, the three tasks should produce the following user interface:

Function: Ask for command.

It is a statement using "scanf("%d" ...)".
• Note #1. You can assume that the user always inputs integers.
• Note #2. You can assume that the user always inputs from 1 to 4.

Based on the user input, your program should carry out different functions:
• Command is 1: the player wants to reveal a hidden cell, go to "Function: Reveal a cell".
• Command is 2: the player wants to flag a hidden cell, go to "Function: Flagging Function".
• Command is 3: the player wants to un-­-flag a flagged cell, go to "Function: Flagging Function".
• Command is 4: the player wants to quit the game, the program is then terminated.

Function: Reveal a cell.

Now the user decides to reveal a cell.

First, the program has to ask for the location of the cell. Two numbers are involved:
1. The row number R, in the range [0, 8] inclusively;
2. The column number C, in the range [0, 9] inclusively.

Let us denote this location as (R, C).

Input Validation. If the player inputs (R, C), but:

• R > 8 or R < 0,
• C > 9 or C < 0,
• (R, C) is a revealed cell, or
• (R, C) is a flagged cell,

then (R, C) is an invalid location. Your program should:

• Print the message "Invalid Location";
• Then, ask the user for the next (R, C) pair until (R, C) specifies a valid location.
• Note that (R, C) is valid only when (R, C) is a hidden cell in the display map.

Game-­-Over Condition. If (R, C) is a bomb in the real map, then the player loses the game. Your program should:

• Print the map with all bombs' location revealed.
• Terminate the program.

Else if (R, C) is not bomb, then we will reveal such a cell in the next function, Function: Cell Reveal Function.

Function: Cell Reveal Function.

Again, we assume that the location specified by the user (R, C). (R, C) is valid when it is:
• a hint number in the real map, or
• an empty cell in the real map.

In the real map, (R, C) is a hint number. Your program should change the location (R,
C) in the "display map": hidden cell → hint number.

In the real map, (R, C) is an empty cell. This task will be one of the major challenges of this project. Therefore, we set up two different tasks at different difficulty levels.

1. Basic reveal task: Your program should change the location (R, C) in the "display map": hidden cell → empty cell.

2. Bonus reveal task: when the user reveals an empty cell, your program should
recursively reveal neighboring cells.

If the next revealed cell is also an empty cell, the recursive revealing process continues.

If the next revealed cell is (1) a hint number, (2) an already-­-revealed cell, or (3) a flagged cell, then the recursive revealing process stops.

The recursive revealing process is depicted in the following:

No matter your program implements the basic or the bonus revealing tasks, when the reveal process stops, your program should check if the player wins the game or not.

Condition: Winning Condition

You should implement a different winning condition as the one used in the original minesweeper. The player wins the game if all the following conditions are both satisfied.

• The locations of all bombs are flagged, and
• Cells that are not bombs are all revealed.

If the player wins the game, then the program should terminate. Else, the player continues to play.

Bonus Winning Condition. If you implement the winning condition in the original minesweeper game, bonus points will be granted.

However, since this is a bonus, you have to formulate and to implement the original minesweeper winning condition. No guidelines would be given.

Function: Flagging Function

A flagged cell means that the player states that the cell is a potential location of a bomb.

• The player can only flag a hidden cell.
• The player can only un-­-flag a flagged cell.

Like the steps taken in revealing a cell, your program should keep on asking the user until the user provides you the correct row-­-column pair.


Attachment:- project-spec.rar

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M91583609
  • Price:- $160

Guranteed 48 Hours Delivery, In Price:- $160

Have any Question?


Related Questions in C/C++

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As