Implements the features of the minesweeper game

Assignment Help C/C++ Programming
Reference no: EM13910680

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 <stdio.h> 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

Reference no: EM13910680

Questions Cloud

2-d environment : Write a class called point for the 2-D environment. Select appropriate variable(s). Write constructors. Write access methods for the variables.
The focus is to write sql queries that combine data : This is the final installment of the project! The focus is to write SQL queries that combine data from both Mondial and GapMinder (GM). For most queries you will need both Mondial and GM data, so you may need to use your bridge table(s).
Difference between the interest expense and interest paid : What was the difference between the interest expense and interest paid in 2013-How much long-term debt will mature in 2014
Meqa assignment 1 : MEQA Assignment 1, 1. Estimate an empirical demand function for QuickKits™.2. Interpret the estimated demand function for QuickKits™.3. Make pertinent recommendations to senior management based on the empirical demand function.
Implements the features of the minesweeper game : 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 - write a Windows Console Application that implements mos..
Quality control purposes : We want to take a sample of 100 items out of a large batch for quality control purposes-Based on past history-the proportion of defective items is 4%-Can we use the normal approximation to the binomial distribution to find the probability of findi..
Major suppliers and leadership : Analyze each company's history, product / services, major customers, major suppliers, and leadership, and provide a synopsis of each company.Identify three (3) profitability ratios that creditors may be interested in. Calculate the ratio for each com..
Describe the role of, and the interaction of the asic : Describe the role of, and the interaction of the ASIC, the AASB and the ASX in the regulation of financial reporting in Australia.  Include in your answer an outline the regulatory document each of these bodies produce.
How you solved the characteristic equation : How you solved the characteristic equation to find the complimentary solution, Template you used to find particular solution and How you found the values of arbitrary constants to solve the initial value problem

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Write a c program to calculate

Write a C program to calculate the following Sum: Sum=1-x2/2! +x4/4!-x6/6!+x8/8!-x10/10! */

  Program to play lottery

The program randomly generates a Lottery of a three-digit number ( any number from 100 to 999), prompts the user to enter a three-digit number, and determines whether the user wins according to the subsequent rule:

  Contact details of a customer changes

In case the contact details of a customer changes, Dwayne needs to delete the previous entry and add a new entry for the respective customer.

  Write a program that allows two players to play a game

Write a program that allows two players (player X and player O) to play a game of tic-tac-toe. Use a two- dimensional char array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk ..

  What mechanism allows the overloaded subscript operator

What mechanism allows the overloaded subscript operator [] to be used on the left side of an assignment statement, like this: v[2] = 22?

  Function called timesten that returns back

Write a function called timesTen that returns back to the caller the value passed into the function multiplied by 10. If the value passed into the function is negative, the function also returns the string

  Pixels down the right of the window

The blue and red values of the pixels across the top of the window are all the same, where the blue is at its maximum value while red is at its minimum value. The green values of the pixels down the right of the window are all the same, where gree..

  Write statements to prompt for and read

Write statements to prompt for and read the user's full name using a Scanner variable.

  Display a list of items and the location in the store

The program should display a list of items and the location in the store. The user must be able to enter the items and location in the store. You will use a class for the items. For this assignment you will implement creating the list, adding eleme..

  Write an iterative version and a recursive version

Write a main program that illustrates the work of your functions. E.g., if a[ ]={1,2,3,3,4,5} then 3 occurs 2 times and 7 occurs 0 times.

  The limit on the amount of wage income

If the government raised the limit on the amount of wage income that is subject to the F.I.C.A. tax, this would: A. Move the Lorenz curve further from the line of income equality  B. Have no effect on the Lorenz curve

  Write a program manipulating a 2-dimensional array

Write a program manipulating a 2-dimensional array. Create constants to represent your number of students and number of assignments.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd