click to check a cell, shift-click to "mark" a mine

AP Java 2 Assignment 1:
Minesweeper

Background

In this assignment you will be recreating the Microsoft Minesweeper game. If you are not familiar with minesweeper you should play the game until you are. You can find it from the Start Menu: Start |Programs | Accessories | Games | Minesweeper

Program Requirements

  1. Your minesweeper game will be a two dimensional array of buttons. Use constants for the number of rows and columns.
  2. The number of bombs should also be specified by a constant, e.g., nBOMBS.
  3. If you click on a cell that contains a bomb, the game ends and all the bombs are displayed
  4. If you click on a cell that does not contain a bomb, a number appears at that location indicating the number of neighbors that DO contain bombs. Recall that each position has at most 8 neighbors. Note that the cells on the boundary have fewer than 8 neighbors. For example, a corner has only three neighbors.
  5. if the user clicks on a cell and no number appears, then there are no bombs surrounding that cell. Your applet should then recursively keep marking those surrounding cells that are not surrounded by bombs.
  6. The game should end when all the cells that do not contain bombs have been marked (assuming that you have not been blown up by then!)
  7. Your game must use the Random class to randomly place the mines.
  8. Submit your .java file (as an attachment) with the URL of your finished applet to mrsimon@lycos.com.

Alternative Assignment: The Game of Life

If you want an alternative to Minesweeper, you could write your own version of the The Game of Life. The Game of Life isn't what you think, it's a program that simulates how bacteria might grow. It's another program that is well suited to using a two dimensional array of buttons. You can find examples and descriptions at the following websites:

Hints to help you complete this assignment

Thanks to Timmy Yee, Kenneth Chan and Sam Schreiber for their help with this assignment