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.


Variable Index

 o FILL_ALIVE
Fill the Grid with living cells.
 o FILL_DEAD
Fill the Grid with dead cells.
 o FILL_RANDOM
Fill the Grid randomly.
 o maxAge
The maximum age of Cells in the Grid.
 o OLD_ALIVE
Used to construct living Cells with maximum age.
 o OLD_DEAD
Used to construct dead Cells with maximum age.

Constructor Index

 o Grid(int, int)
Construct a new Grid of specified width and height and fill the Grid with dead Cells.
 o Grid(int, int, int)
Construct a new Grid of specified width and height and fill the Grid's Cells.

Method Index

 o fill(int)
Fill the Grid with dead cells, living cells, or with a random pattern.
 o getAge(int, int)
Get the age of the Cell at the specified x-y coordinates.
 o getMaxAge()
Get the maximum age for this Grid.
 o isAlive(int, int)
Is the Cell at the specified x-y coordinates alive?
 o neighbors(int, int, boolean)
Calculate how many neighbors a Cell has.
 o nextGen(int, int, boolean, int, boolean)
Produce the next generation of a Cell.
 o setCell(int, int, Grid. Cell)
Set the Cell at the specified x-y coordinate to a given Cell.
 o setMaxAge(int)
Set the maximum age for this Grid.
 o setOldAlive(int, int)
Set the Cell at the specified x-y coordinates to a living Cell of maximum age.
 o setOldDead(int, int)
Set the Cell at the specified x-y coordinates to a dead Cell of maximum age.
 o setSize(int, int, boolean)
Set the width and height of the Grid.

Variables

 o maxAge
 protected int maxAge
The maximum age of Cells in the Grid.

 o OLD_ALIVE
 public static final int OLD_ALIVE
Used to construct living Cells with maximum age.

 o OLD_DEAD
 public static final int OLD_DEAD
Used to construct dead Cells with maximum age.

 o FILL_DEAD
 public static final int FILL_DEAD
Fill the Grid with dead cells.

 o FILL_ALIVE
 public static final int FILL_ALIVE
Fill the Grid with living cells.

 o FILL_RANDOM
 public static final int FILL_RANDOM
Fill the Grid randomly.

Constructors

 o 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
 o 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.

Methods

 o 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.
 o 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.
 o getMaxAge
 public final int getMaxAge()
Get the maximum age for this Grid.

 o setMaxAge
 public void setMaxAge(int maxAge)
Set the maximum age for this Grid.

Parameters:
maxAge - The maximum age.
 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o 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