CS335
Fall, 2008
Programming Assignment 1 (40 points)
Due: October 16 (Thursday)


1. Problem Description

Write a Java application, Bombs.java, to play a game similar to
"minesweeper".


The application first displays a GUI like the one shown below
to ask the user for the number of rows r ( r >= 5 ), the number
of columns c ( c >= 5 ), and the number of bombs b ( b >= 1 )
(the default is 5, 5, and 1 respectively).
When the user presses the start button a grid of "r x c" cells
with b having bombs in them and a "Restart" button is displayed
(see the following example).

The face of each cell is blank (or anything you want).  Play proceeds
by allowing the user to click on any cell in the grid.  The goal
is to avoid clicking on a cell where a bomb is located.  If the user
clicks on a bomb, the game ends and the entire board is revealed.
When the user selects a cell which is not a bomb, the cell face
changes color and displays a number which represents the number
of its neighboring cells which contain bombs.  A cell has 8
neighbors: the north, south, east and west cells, together with
the four diagonal ones.  Cells on the boundary of the grid have
fewer neighbors (only five for a cell on an edge, and corner
cells only have three).  The user scores a victory by clicking
on all cells which are not bombs without hitting a bomb.
The user can press the restart button at any time to restart the
game with the same number of rows, columns and bombs that he
originally input, but the bombs should be in different locations.
The number of bombs input by the user should be less than one
half of the available cells.



2. Implementation Details

Implement the grid of cells and the methods to manage the cells for
this game as a java class.  Use private data to store the state of
the board, such as which cells have been selected and which contain
bombs.  With accessor and mutator methods you can control the game
from the driver, which should allocate an instance of the class to
set up the game.  The constructor of the class must allow the driver
program to assign a variable grid size (not necessarily square),
and a variable number of bombs.  The class should assign bomb
locations randomly.

In terms of game play, you should provide a way to restart the game
(start a new game) at any point.  You may assume that the grid size
is fixed once the aplication begins to execute, so that the number of
cells and bombs remains constant.  Starting a new game must reset
the state of the board, changing the faces of all cells to blank (or
the way you chose to have at the beginning) and assigning new random
bomb locations.  You must print a message stating when the user has
won or lost.

You are free to use layout manager tools in this assignment,
although it is not necessary in order to implement the game.


3. What to Turn In

Mail your program (in one file) and external documentation
(in another file) to "xuwei.liang@uky.edu" separately on or before
the due date.  Name your driver "Bombs.java" and put it
in the first (comment) line of the driver.  The names of the
other classes of your program are not important.
Your java code must contain internal documentation.
The external documentation named YourLastName.txt should
describe the "project specifications" and the "implementation
details".