Question
The program you will design and build implements a game called Miensfeld. This is a one player game (you against the computer) using a fancy
The program you will design and build implements a game called Miensfeld. This is a one player game (you against the computer) using a "fancy" display, similar to the Calculator.
In Miensfeld, your player, Timmy, is located on one side of a 8 by 10 cell area minefield. Your task is to move Timmy safely through the minefield to get to the other side, earning points as you move.
o | | | | | | | | | Y |S 1| | | | | | | | MINES ---|---|---|---|---|---|---|---|---|--- | | | | | | | | | | | S |S 2| | | | | | | | | | ---|---|---|---|---|---|---|---|---|--- | | | | | | | | | S | | | | | | | | | ---|---|---|---|---|---|---|---|---|- FLAGS | | | | | | | | | S |S 1|S 1| | | | | | | | | ---|---|---|---|---|---|---|---|---|--- | | | | | | | | | | | S |S |S | | | | | | | ---|---|---|---|---|---|---|---|---|--- | | | | | | | | | SCORE S |S |S | | | | | | | _ _ ---|---|---|---|---|---|---|---|---|--- | | | | | | | | | | | | | |_| |_| S |S | | | | | | | | ---|---|---|---|---|---|---|---|---|--- | | | | | | | | | S |S |S | | | | | | |
Moving Around
To move about in the minefield, you use the keyboard. You can move Timmy in any of the 8 directions from his current position by using the 8 keys surrounding the 'j' key:
y | u | i --|---|-- h | | k --|---|-- n | m | ,
As Timmy moves through the field, he indicates safe cells (cells known to not contain a mine) on his map.
Detecting Mines
To help Timmy find his way through the mines, he is equipped with a "proximity probe" which tells him how many mines there are in the 8 cells surrounding him (today's modern Army has all the coolest gadgets). Unfortunately, the probe cannot tell him where those mines are, just how many.
Planting Flags
However, Timmy is also equipped with a limited number of hi-tech indicating flags to use to indicate cells to avoid by others behind him. He may plant a flag (using the keyboard) in any of the 8 surrounding cells when he suspects there is mine there. The keys to plant a flag are the shifted versions of the movement keys:
Y | U | I --|---|-- H | | K --|---|-- N | M | <
When planted, the flag will indicate whether there is a mine there or not.
Earning Points
Timmy earns 1 point for each new safe cell he finds by moving into it. In addition, he earns 2 points for each flag he plants correctly in a cell that contains a mine. However, he loses 1 point for each flag he plants in a cell that does not contain a mine.
If Timmy successfully makes it to the other side of the minefield, he earns a bonus of 10 points.
The game ends when Timmy either reaches the other side of the field :-), or gets blown up by stepping on a mine :-(.
Field Set-up
When the game begins, the computer randomly places a number of mines in the field and issues Timmy the same number of flags (how many mines and flags to place is explained below). In addition, some of Timmy's predecessors have already mapped some of the safe cells in the field. The number of known safe cells is a random amount, however, it will never exceed 20 cells. These known safe cells (for which there are no points) are always as far to the left of the field, and always adjacent to other safe cells in the same row or the left boundary of the field.
The number of mines in the field is determined by the level of difficulty the user chooses to play. The levels are:
Level | Number of Mines | Number of Flags |
---|---|---|
Easy | 6 | 6 |
Moderate | 11 | 11 |
Hard | 16 | 16 |
Impossible | 20 | 20 |
The player may choose to play the game as many times as they want (with new minefields and Timmy's each time) At the beginning of each game, Timmy starts in the upper left cell of the field.
Implementation Hints and Help
You should think about this project before you attempt to write any code.
What modules will you need?
What does each do?
What data structures will you use to represent the information needed to proceed with the game?
What functions will you need?
What kind of information should they be given and what should they return?
USE THE FIVE STEP DESIGN PROCESS
Then you should begin tackling the modules one by one; writing the algorithms for the functions and then coding them in C and testing them. Remember to develop and test your program incrementally like we did for the calculator - using your own "throw away" drivers to test. (You may turn these in, and we MAY look at them, but we are primarily interested in the final product).
This file contains the interface for the display module for the miensfeld game. User defined types and function prototypes are specified and explained. */ /* The following data type, Glif, is used by the show_glif() function to specify the glif image to appear on the board. */ enum Glif {TIMMY, SAFE, EMPTY, FLAG, MINE, FL_MINE, EXPLODE }; typedef enum Glif Glif; void draw_board(void); /* This function initializes the game board. It should be called at the beginning of each game. It is given and returns nothing. */ void clear_screen(void); /* This function terminates the display. It should be called at the end of the program. It is given and returns nothing. */ void show_glif(Glif glif, int row, int col, int Adj_count); /* This function draws a specified glif on the board at the row and column specified. The glif is indicated by the Glif type value; one of the symbols listed in the enum type above. The adjecency count, if non-zero, is displayed in the lower right of the glif. It is given a Glif, and three integers and returns nothing. */ void update_mines(int num); void update_flags(int num); void update_score(int num); /* These three functions are given an integer in the range 0 to 99 and update the display of the mines, flags and score, respectively. They all return nothing. */ void write_message(int line, char *msg); /* This function is used to write messages in the left area of the screen. It is given an integer indicating the line of the display (0 to 23) to place the message, given as a string. It returns nothing. The function only displays the first 25 characters of msg, or up to the first ' ' in the string. If no newline is present, msg replaces the entire line on the screen. If a newline is present in the string, only characters up to the newline replace those on the line, leaving the remainder of the line intact. */
Step 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