< Back

Minesweeper

If you have done anything on Windows, you have likely played Minesweeper. It is a puzzle game that requires tracking down mines that are randomly placed in a 2-dimensional grid. The number in each grid cell describes the number of mines in the 8 adjacent cells. One of the more interesting features of minesweeper is how it handles 0's. If you click on a cell that does not have any adjacent mines (They also store 0), then it uncovers all adjacent cells with a 0 stored in it!


Setup

Create a directory assignment6 under assignments in your cs170 directory. All code for the assignment should be stored in this directory.

cd ~/cs170/assignments
mkdir assignment6 
cd assignment6

Details

Write a program that uses Qt and allows the user to play a regular game of Minesweeper. Your play field consists of a 2-dimensional grid (You need at least a 10 x 10 grid for this assignment) of squares that are initially empty. As the user clicks on a square, you should reveal whether there was a mine under that location. If there was not a mine, you should reveal how many mines are adjacent to that location.

If the number of mines at the location was 0, you should also uncover all of the adjacent locations. This allows for the group uncover of ALL adjacent locations which have exactly 0 adjacent mines.

If the user clicked on a mine, you should identify the location of all of the mines. You should identify which mine the user clicked on by changing the color of the symbol you are using for a mine. For example, if you are using the 'X' character to represent a mine in the play field, the mine the user clicked on could be colored red.

If the user is able to successfully uncover all of the non-mine locations, you should reveal all of the mine locations as if they had clicked on a mine. However, none of the mines should be identified as the one the user clicked on. You should also display a message informing the user that they won.


"Hacker" Prompt

  1. Flags: Add the ability for the user to right click a square they think is a mine. This should place some symbol on top of the square, and should prevent the user from clicking and revealing that square. The user should be able to right click on a flagged square to unflag the square.

  2. Difficulty Levels: Add buttons to the bottom of the canvas that allows the user to select a difficulty level for their next game. There should be three levels of difficulty: Easy, Medium, and Hard. An easy game should be the 10 x 10 board with 10 mines. A medium game is 16 x 16 with 40 mines. A hard game is 30 x 16 with 99 mines.