All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class life.Life

java.lang.Object
   |
   +----life.Life

public class Life
extends Object
implements Runnable
A Life object generates life. Essentially, a Life object encapsulates a grid of cells, and changes the state of the grid in successive generations according to the rules of the game of Life. To display the life generated by a Life object, use a LifeDisplay object.

See Also:
Grid, LifeDisplay

Variable Index

 o CONTINUOUS
Generate life until the user aborts.
 o STEP
Generate one generation of life.

Constructor Index

 o Life(LifeDisplay)
Creates a new Life with the given LifeDisplay.

Method Index

 o generate(int)
Start generating life.
 o getAge(int, int)
Get the age of the cell at the specified x-y coordinate.
 o getDelay()
Get the delay between frames.
 o getDirtyCells()
Return the cells in the grid that have changed since the last generation and therefore need to be repainted.
 o getGeneration()
Get the current generation number.
 o getGridHeight()
Get the height of the grid.
 o getGridWidth()
Get the width of the grid.
 o getWraparound()
Are neighbors counted using wraparound?
 o isAlive(int, int)
Is the cell at the specified x-y coordinate alive?
 o lifeFunction(int, int)
Generate the next generation of the cell at the specified x-y coordinates.
 o randomize()
Randomize the current grid and reset the generation number to zero.
 o reset()
Reset the current grid to dead cells and reset the generation number to zero.
 o run()
Generate life in a separate thread.
 o setCell(int, int, Grid. Cell)
Copy the age and life status (i.e., living or dead) from the specified cell into the cell at the specified x-y coordinate of the grid.
 o setDelay(long)
Set the delay between frames.
 o setGeneration(int)
Set the current generation number.
 o setGridSize(int, int)
Set the width and height of the grid.
 o setMaxAge(int)
Set the maximum age of cells in the grid.
 o setOldAlive(int, int)
Set the cell at the specified x-y coordinate to a living cell with the maximum allowable age.
 o setOldDead(int, int)
Set the cell at the specified x-y coordinate to a dead cell with the maximum allowable age.
 o setWraparound(boolean)
Instruct the Life to either use or not use wraparound when counting neighbors.
 o stop()
Stop generating life.

Variables

 o CONTINUOUS
 public static final int CONTINUOUS
Generate life until the user aborts. Used as a value for runMode.

 o STEP
 public static final int STEP
Generate one generation of life. Used as a value for runMode.

Constructors

 o Life
 Life(LifeDisplay ld)
Creates a new Life with the given LifeDisplay.

Methods

 o getGridHeight
 int getGridHeight()
Get the height of the grid.

 o getGridWidth
 int getGridWidth()
Get the width of the grid.

 o setGridSize
 void setGridSize(int w,
                  int h)
Set the width and height of the grid.

Parameters:
w - The new width of the grid.
h - The new height of the grid.
 o getGeneration
 int getGeneration()
Get the current generation number.

 o setGeneration
 void setGeneration(int g)
Set the current generation number.

Parameters:
g - The new generation number.
 o getDelay
 long getDelay()
Get the delay between frames.

 o setDelay
 void setDelay(long delay)
Set the delay between frames.

Parameters:
delay - The new delay (in milliseconds) between frames.
 o getWraparound
 boolean getWraparound()
Are neighbors counted using wraparound?

 o setWraparound
 void setWraparound(boolean wraparound)
Instruct the Life to either use or not use wraparound when counting neighbors.

Parameters:
wraparound - If true, use wraparound. If false, don't use wraparound.
 o getDirtyCells
 Vector getDirtyCells()
Return the cells in the grid that have changed since the last generation and therefore need to be repainted.

 o reset
 synchronized void reset()
Reset the current grid to dead cells and reset the generation number to zero.

 o randomize
 synchronized void randomize()
Randomize the current grid and reset the generation number to zero.

 o setCell
 void setCell(int x,
              int y,
              Grid. Cell c)
Copy the age and life status (i.e., living or dead) from the specified cell into the cell at the specified x-y coordinate of the grid.

Parameters:
x - The x coordinate of the cell.
y - The y coordinate of the cell.
c - The cell to be copied from.
 o isAlive
 boolean isAlive(int x,
                 int y)
Is the cell at the specified x-y coordinate alive?

 o getAge
 int getAge(int x,
            int y)
Get the age of the cell at the specified x-y coordinate.

 o setMaxAge
 void setMaxAge(int maxAge)
Set the maximum age of cells in the grid.

Parameters:
maxAge - The new maximum age of cells in the grid.
 o setOldAlive
 void setOldAlive(int x,
                  int y)
Set the cell at the specified x-y coordinate to a living cell with the maximum allowable age.

Parameters:
x - The x coordinate of the Cell.
y - The y coordinate of the Cell.
 o setOldDead
 void setOldDead(int x,
                 int y)
Set the cell at the specified x-y coordinate to a dead cell with the maximum allowable age.

Parameters:
x - The x coordinate of the Cell.
y - The y coordinate of the Cell.
 o lifeFunction
 void lifeFunction(int x,
                   int y)
Generate the next generation of the cell at the specified x-y coordinates.

Parameters:
x - The x coordinate of the Cell.
y - The y coordinate of the Cell.
 o run
 public void run()
Generate life in a separate thread.

 o generate
 void generate(int runMode)
Start generating life.

Parameters:
runMode - The mode in which to generate life.
See Also:
runMode
 o stop
 void stop()
Stop generating life.


All Packages  Class Hierarchy  This Package  Previous  Next  Index