The rules for the game are really very simple:
+---+---+---+
| 1 | 2 | 3 |
+---+---+---+
| 4 | 5 | 6 | So a cell at 5, would need to check its neighbors at 1,2,3,4,6,7,8,9.
+---+---+---+
| 7 | 8 | 9 |
+---+---+---+
If a cell is at a border, then treat all locations off-board as empty.
Here are a few sample illustrations to help demonstrate the rules. A C means the square is occupied by a cell.
+---+---+---+
| C | | |
+---+---+---+
| | C | | This center cell would die (become an empty square) in the next generation
+---+---+---+ since it only has 1 neighbor.
| | | |
+---+---+---+
+---+---+---+
| | | |
+---+---+---+
| C | C | C | This center cell would die (become an empty square) in the next generation
+---+---+---+ since it has 4 neighbors.
| C | | C |
+---+---+---+
+---+---+---+
| C | | |
+---+---+---+
| | | | This center cell would be born (become an occupied square) in the next generation
+---+---+---+ since it has exactly 3 neighbors.
| C | | C |
+---+---+---+
Your program should run as a GUI application in a JFrame. You should have a JPanel-derived class containing 4 buttons, a JLabel, a text entry field and a drawing area.
The buttons consist of:You should display the current generation number (turn number) in a JLabel.
You should allow the user to enter a delay to use for the animate mode. The default delay if no other entry has been made is 100ms.
In the drawing area, you should display the grid representing the squares that hold the cells. The default grid size should be 20 x 20. (For extra credit, you may allow user specified grid sizes to be entered.)
When starting the game, the user should be allowed to click with the mouse inside each cell to make that cell occupied or empty. Clicking on an empty cell makes it occupied. Clicking on an occupied cell makes it empty. Once the user presses the Step or Run button, mouse clicks in the grid area are ignored until the clear button is pressed.
When a square is occupied it should be filled in with the color of your choice. All the squares should be the same color. (For extra credit, newly born cells in each generation can be colored with a different color from the older cells in a generation).
Generation 0 (Start)
+---+---+---+---+---+
| | C | | | |
+---+---+---+---+---+
| | | C | | |
+---+---+---+---+---+
| C | C | C | | |
+---+---+---+---+---+
| | | | | |
+---+---+---+---+---+
Generation 1
+---+---+---+---+---+
| | | | | |
+---+---+---+---+---+
| C | | C | | |
+---+---+---+---+---+
| | C | C | | |
+---+---+---+---+---+
| | C | | | |
+---+---+---+---+---+
Generation 2
+---+---+---+---+---+
| | | | | |
+---+---+---+---+---+
| | | C | | |
+---+---+---+---+---+
| C | | C | | |
+---+---+---+---+---+
| | C | C | | |
+---+---+---+---+---+
Generation 3
+---+---+---+---+---+
| | | | | |
+---+---+---+---+---+
| | C | | | |
+---+---+---+---+---+
| | | C | C | |
+---+---+---+---+---+
| | C | C | | |
+---+---+---+---+---+
Generation 4
+---+---+---+---+---+
| | | | | |
+---+---+---+---+---+
| | | C | | |
+---+---+---+---+---+
| | | | C | |
+---+---+---+---+---+
| | C | C | C | |
+---+---+---+---+---+