DOC PREVIEW
UE CS 215 - CS 215 ­ Fundamentals of Programming II

This preview shows page 1-2-3-4 out of 11 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS 215 - Fundamentals of Programming IISpring 2011 - Project 430 pointsOut: February 21, 2011Due: March 16, 2011 (Wednesday after spring break)Reminder: Programming Projects (as opposed to Homework problems) are to be your own work. See syllabus for definitions of acceptable assistance from others.Reminder 2: THIS MATERIAL WILL BE ON THE MIDTERM EXAM!! START WORKING NOW!!!Minesweeper is game with a two-dimensional grid playing field. Each grid location (called a cell) may contain a mine. Initially, all cells are covered, hiding any mines from the player. Play is conducted as follows: ● A cell may be uncovered. If a mine is uncovered, the game is lost. Otherwise, the total number of mines in any adjacent grid cells (all 8 directions) is shown in the cell. Using these numbers, together with skill, judgment, and a little luck, a player should be able to determine the locations of all mines. ● A covered cell may be marked. This is used to indicate a grid cell where the player thinks a mine is. ● A covered cell may be unmarked. This removes a mark from a grid cell. ● The game is won if all grid cells have been either marked or uncovered, and the number of marked grid cells is the same as the number of mines. I.e. the player has identified all the mines without uncovering any of them. A graphical version is available on Ubuntu Linux machines under Applications->Games->Mines.Consider the following specification for a SweeperGrid class that represents the Minesweeper playing field. Each grid cell contains a SweeperCell object, that contains information regarding the state of the cell. (The SweeperCell class is provided and is explained below.) Cell locations are given as coordinates (row, col) where (0,0) is the upper left-hand corner of the grid. Specification for SweeperGrid Class Data Attributes For this project, a SweeperGrid is modeled using a dynamically-allocated two-dimensional array of SweeperCells, as demonstrated in lecture, to allow grids of differing sizes to be created. Thus the data attributes include at least those shown below. You may add additional appropriate attributes.Objects Type Namenumber of rows int numRowsnumber of columns int numColumnsnumber of bombs in the grid int numBombspointer to grid SweeperCell** grid02/20/2011 Page 1 of 11 D. HwangOperations ● Explicit-value constructor - receives the number of rows and columns, and a density percentage. Default values are given below. If initialRows or initialCols is less than 5 (to make sure the grid is large enough) or if the density is not between 25 and 75 (to make sure not all cells are empty or all cells contain bombs) the constructor should print out an error message and exit. Otherwise the constructor should dynamically allocate a two-dimensional SweeperCell grid of the specified size as demonstrated in lecture. The constructor places density percentage number of bombs in the grid, and computes the number of adjacent cells containing bombs for each cell. Bombs are to be placed randomly into the grid in the density specified. Density is specified as an integer between 25 and 75 that represents the percentage of cells that will contain bombs. (E.g. 25 means 25%, or one-fourth, of the cells will contain bombs.) The easiest way to do this is to loop through the grid cells, and for each cell use the built-in random number generator to pick a number between 1 and 100. If the number generated is less than the density percentage, then place a bomb in the cell. Note: the random number generator under g++ works as follows. The generator is seeded using srand() (defined in <cstdlib>), which receives a long integer. We want the game to be different each time, so most programmers use the result of the time function (defined in <ctime>) to seed the generator by using: srand(time(0));This should be done once before the first use of the random number generator. (Note: if you want the same numbers to be generated each time, e.g., when testing, use a constant as the argument to srand(), but your final submission should use time()).The function rand() returns the next random integer between 0 and RAND_MAX. Scaling this result to numbers between 1 and 100 can be done by the following code fragment: rand() % 100 + 1Recall that % is the remainder operator in C++. (As shown in the sample run below, the actual density percentage produced by this method can be off by quite a bit, but it should be within 10% or so.) Analysis Objects Default Type Movement Namenumber of rows 5 int received initialRowsnumber of columns 5 int received initialColsdensity percentage 25 int received density● Copy constructor - creates a new SweeperGrid that is identical to an existing one. Analysis 02/20/2011 Page 2 of 11 D. HwangObjects Type Movement Namesource SweeperGrid object SweeperGrid received source● Destructor - deallocates the grid Analysis - no objects ● operator= - overloaded assignment operator function. Makes an existing SweeperGrid object identical to the source SweeperGrid object. Analysis Objects Type Movement Namesource SweeperGrid object SweeperGrid received source● GetRows - returns the number of rows in the grid Analysis Objects Type Movement Namenumber of rows int returned numRows● GetColumns - returns the number of columns in the grid AnalysisObjects Type Movement Namenumber of columns int returned numColumns● GetBombs - returns the number of bombs in the grid Analysis Objects Type Movement Namenumber of bombs int returned numBombs● GameWon - returns true if the game has been won Analysis Objects Type Movement Namewin result bool returned ---02/20/2011 Page 3 of 11 D. Hwang● PlaceBomb - place a bomb in the grid cell at location (row, col). Note this function must recompute the number of adjacent bombs of the cell's neighbors (all 8 directions). If the location (row, col) is not within the bounds of the grid, throws an out_of_range exception. (See notes below.)Analysis Objects Type Movement Namerow index int received rowcolumn index int received col● RemoveBomb - remove a bomb in the grid cell at location (row, col). Note this function must recompute the number of adjacent bombs of the cell's neighbors (all 8 directions). If the location (row, col) is not within the bounds of the grid, throws an out_of_range exception. (See notes below.)Analysis Objects Type Movement Namerow index int received rowcolumn index int received col● Uncover - uncovers the grid cell at


View Full Document

UE CS 215 - CS 215 ­ Fundamentals of Programming II

Documents in this Course
Lecture 4

Lecture 4

14 pages

Lecture 5

Lecture 5

18 pages

Lecture 6

Lecture 6

17 pages

Lecture 7

Lecture 7

28 pages

Lecture 1

Lecture 1

16 pages

Lecture 5

Lecture 5

15 pages

Lecture 7

Lecture 7

28 pages

Load more
Download CS 215 ­ Fundamentals of Programming II
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view CS 215 ­ Fundamentals of Programming II and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view CS 215 ­ Fundamentals of Programming II 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?