All Packages Class Hierarchy This Package Previous Next Index
Class life.Grid
java.lang.Object
|
+----life.Grid
- public class Grid
- extends Object
A two-dimensional grid of Cells.
-
FILL_ALIVE
- Fill the
Grid with living cells.
-
FILL_DEAD
- Fill the
Grid with dead cells.
-
FILL_RANDOM
- Fill the
Grid randomly.
-
maxAge
- The maximum age of
Cells in the Grid.
-
OLD_ALIVE
- Used to construct living
Cells with maximum age.
-
OLD_DEAD
- Used to construct dead
Cells with maximum age.
-
Grid(int, int)
- Construct a new
Grid of specified width and height
and fill the Grid with dead Cells.
-
Grid(int, int, int)
- Construct a new
Grid of specified width and height
and fill the Grid's Cells.
-
fill(int)
- Fill the
Grid with dead cells, living cells,
or with a random pattern.
-
getAge(int, int)
- Get the age of the
Cell at the specified x-y coordinates.
-
getMaxAge()
- Get the maximum age for this
Grid.
-
isAlive(int, int)
- Is the
Cell at the specified x-y coordinates alive?
-
neighbors(int, int, boolean)
- Calculate how many neighbors a
Cell has.
-
nextGen(int, int, boolean, int, boolean)
- Produce the next generation of a
Cell.
-
setCell(int, int, Grid. Cell)
- Set the
Cell at the specified x-y coordinate
to a given Cell.
-
setMaxAge(int)
- Set the maximum age for this
Grid.
-
setOldAlive(int, int)
- Set the
Cell at the specified x-y coordinates to a
living Cell of maximum age.
-
setOldDead(int, int)
- Set the
Cell at the specified x-y coordinates to a
dead Cell of maximum age.
-
setSize(int, int, boolean)
- Set the width and height of the
Grid.
maxAge
protected int maxAge
- The maximum age of
Cells in the Grid.
OLD_ALIVE
public static final int OLD_ALIVE
- Used to construct living
Cells with maximum age.
OLD_DEAD
public static final int OLD_DEAD
- Used to construct dead
Cells with maximum age.
FILL_DEAD
public static final int FILL_DEAD
- Fill the
Grid with dead cells.
FILL_ALIVE
public static final int FILL_ALIVE
- Fill the
Grid with living cells.
FILL_RANDOM
public static final int FILL_RANDOM
- Fill the
Grid randomly.
Grid
public Grid(int width,
int height,
int how)
- Construct a new
Grid of specified width and height
and fill the Grid's Cells.
- Parameters:
- width - The width of the
Grid.
- height - The height of the
Grid.
- how - Indicates how to fill the
Grid.
- See Also:
- fill
Grid
public Grid(int width,
int height)
- Construct a new
Grid of specified width and height
and fill the Grid with dead Cells.
- Parameters:
- width - The width of the
Grid.
- height - The height of the
Grid.
setCell
public final void setCell(int x,
int y,
Grid. Cell c)
- Set the
Cell at the specified x-y coordinate
to a given Cell.
- Parameters:
- x - The x coordinate.
- y - The y coordinate.
- c - The
Cell to use.
setSize
public void setSize(int w,
int h,
boolean zoom)
- Set the width and height of the
Grid.
- Parameters:
- w - The width.
- h - The height.
- zoom - This
setSize operation is the result of
the user zooming in or out.
getMaxAge
public final int getMaxAge()
- Get the maximum age for this
Grid.
setMaxAge
public void setMaxAge(int maxAge)
- Set the maximum age for this
Grid.
- Parameters:
- maxAge - The maximum age.
nextGen
public boolean nextGen(int x,
int y,
boolean newAlive,
int currentAge,
boolean currentAlive)
- Produce the next generation of a
Cell.
- Parameters:
- x - The x coordinate of the
Cell.
- y - The y coordinate of the
Cell.
- newAlive - The alive value to assign to the
Cell.
- currentAge - The current age of the
Cell.
- currentAlive - The current alive value of the
Cell.
- Returns:
- Indicates whether the current generation differs from the
previous generation in alive or age.
fill
public void fill(int how)
- Fill the
Grid with dead cells, living cells,
or with a random pattern.
- Parameters:
- how - How to fill the
Grid (with living cells,
dead cells, or randomly.
neighbors
public int neighbors(int x,
int y,
boolean wraparound)
- Calculate how many neighbors a
Cell has.
- Parameters:
- x - The x coordinate of the
Cell.
- y - The y coordinate of the
Cell.
- wraparound - Whether to wrap around the
Grid
when counting neighbors.
isAlive
public final boolean isAlive(int x,
int y)
- Is the
Cell at the specified x-y coordinates alive?
- Parameters:
- x - The x coordinate of the
Cell.
- y - The y coordinate of the
Cell.
getAge
public final int getAge(int x,
int y)
- Get the age of the
Cell at the specified x-y coordinates.
- Parameters:
- x - The x coordinate of the
Cell.
- y - The y coordinate of the
Cell.
setOldAlive
public final void setOldAlive(int x,
int y)
- Set the
Cell at the specified x-y coordinates to a
living Cell of maximum age.
- Parameters:
- x - The x coordinate of the
Cell.
- y - The y coordinate of the
Cell.
setOldDead
public final void setOldDead(int x,
int y)
- Set the
Cell at the specified x-y coordinates to a
dead Cell of maximum age.
- Parameters:
- x - The x coordinate of the
Cell.
- y - The y coordinate of the
Cell.
All Packages Class Hierarchy This Package Previous Next Index