/* * LifeCell.java - Java class for an individual cell in the jlife simulation. * * Author : Jeff Mercer * Written: 7/23/99 * Updated: 7/31/99 * JDK Ver: 1.1.8 * * Purpose: A simple class for an individual cell in the Life simulation. * An array of these objects will make up the playing grid. */ public class LifeCell { /********************************* * Data members of LifeCell class *********************************/ final int DEAD=0; // Constant for dead state value. final int ALIVE=1; // Constant for living state value. private int nowState; // Cell's current state. private int futureState; // Cell's future state (aka fate). private double age; // Cell's age in generations. /********************************** * Constructors for LifeCell class **********************************/ public LifeCell() // Default constructor, no parameters. { nowState=DEAD; futureState=DEAD; age=0; } /***************************** * Methods for LifeCell class *****************************************************************************/ // Return the cell's current state as an integer. public int giveState() { return nowState; } /*****************************************************************************/ // Accept a new future state (aka fate) for the cell. Must be an integer. public void acceptFate(int st) { // Only accept valid state values! if (st==ALIVE || st==DEAD) futureState=st; } /*****************************************************************************/ // Return the cell's current age as a double. public double giveAge() { return age; } /*****************************************************************************/ // Update the cell by having it accept it's fate, increment age if necessary // and return the new state as an integer. public int updateCell() { // If cell is surviving, increment it's age... if (nowState==ALIVE && futureState==ALIVE) age++; // ...otherwise, reset the age. else age=0; // Switch cell to it's new state. nowState=futureState; // Return the cell's new state. return nowState; } // End of line. }