| At this point we add all the code for the original
(non-applet) Life game. There are a huge number of
changes just to get all the accesses to work. There
are not, however, any fundamentally new ideas involved.
The "Step" button now makes the Life board advance one step. |
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*; // needed for ActionListener
public class Life extends Applet
{
static int boardSize = 10;
Cell [][] board;
Cell [][] nextBoard;
Button stepButton;
MyCanvas canvas;
/**
* Creates an empty (all cells dead) playing board of the given boardSize.
*/
static Cell[][] emptyBoard (int boardSize)
{
Cell[][] result = new Cell[boardSize][boardSize];
for (int i = 0; i limit) continue;
if (jj <0 || jj> limit) continue;
if (board[ii][jj].getAlive ()) count++;
}
return count;
}
}