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
-
CONTINUOUS
- Generate life until the user aborts.
-
STEP
- Generate one generation of life.
-
Life(LifeDisplay)
- Creates a new
Life with the given
LifeDisplay.
-
generate(int)
- Start generating life.
-
getAge(int, int)
- Get the age of the cell at the specified x-y coordinate.
-
getDelay()
- Get the delay between frames.
-
getDirtyCells()
- Return the cells in the grid that have changed
since the last generation and therefore need to be repainted.
-
getGeneration()
- Get the current generation number.
-
getGridHeight()
- Get the height of the grid.
-
getGridWidth()
- Get the width of the grid.
-
getWraparound()
- Are neighbors counted using wraparound?
-
isAlive(int, int)
- Is the cell at the specified x-y coordinate alive?
-
lifeFunction(int, int)
- Generate the next generation of the cell at the specified
x-y coordinates.
-
randomize()
- Randomize the current grid and reset the generation number
to zero.
-
reset()
- Reset the current grid to dead cells and reset the generation number
to zero.
-
run()
- Generate life in a separate thread.
-
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.
-
setDelay(long)
- Set the delay between frames.
-
setGeneration(int)
- Set the current generation number.
-
setGridSize(int, int)
- Set the width and height of the grid.
-
setMaxAge(int)
- Set the maximum age of cells in the grid.
-
setOldAlive(int, int)
- Set the cell at the specified x-y coordinate to a living cell with
the maximum allowable age.
-
setOldDead(int, int)
- Set the cell at the specified x-y coordinate to a dead cell with
the maximum allowable age.
-
setWraparound(boolean)
- Instruct the
Life to either use or not use wraparound
when counting neighbors.
-
stop()
- Stop generating life.
CONTINUOUS
public static final int CONTINUOUS
- Generate life until the user aborts. Used as a value for
runMode.
STEP
public static final int STEP
- Generate one generation of life. Used as a value for
runMode.
Life
Life(LifeDisplay ld)
- Creates a new
Life with the given
LifeDisplay.
getGridHeight
int getGridHeight()
- Get the height of the grid.
getGridWidth
int getGridWidth()
- Get the width of the grid.
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.
getGeneration
int getGeneration()
- Get the current generation number.
setGeneration
void setGeneration(int g)
- Set the current generation number.
- Parameters:
- g - The new generation number.
getDelay
long getDelay()
- Get the delay between frames.
setDelay
void setDelay(long delay)
- Set the delay between frames.
- Parameters:
- delay - The new delay (in milliseconds) between frames.
getWraparound
boolean getWraparound()
- Are neighbors counted using wraparound?
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.
getDirtyCells
Vector getDirtyCells()
- Return the cells in the grid that have changed
since the last generation and therefore need to be repainted.
reset
synchronized void reset()
- Reset the current grid to dead cells and reset the generation number
to zero.
randomize
synchronized void randomize()
- Randomize the current grid and reset the generation number
to zero.
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.
isAlive
boolean isAlive(int x,
int y)
- Is the cell at the specified x-y coordinate alive?
getAge
int getAge(int x,
int y)
- Get the age of the cell at the specified x-y coordinate.
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.
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.
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.
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.
run
public void run()
- Generate life in a separate thread.
generate
void generate(int runMode)
- Start generating life.
- Parameters:
- runMode - The mode in which to generate life.
- See Also:
- runMode
stop
void stop()
- Stop generating life.
All Packages Class Hierarchy This Package Previous Next Index