com.holub.life
Class Resident

java.lang.Object
  extended by com.holub.life.Resident
All Implemented Interfaces:
Cell

public final class Resident
extends Object
implements Cell

The Resident class implements a single cell---a "resident" of a block.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.holub.life.Cell
Cell.Memento
 
Field Summary
 
Fields inherited from interface com.holub.life.Cell
DUMMY, LOAD, STORE
 
Constructor Summary
Resident()
           
 
Method Summary
 void clear()
          Set the cell and all subcells into a "dead" state.
 Cell create()
          Return a fresh (newly created) object identical to yourself in content.
 Storable createMemento()
          Mementos must be created by Neighborhood objects.
 Cell edge(int row, int column)
          This cell is monetary, so it's at every edge of itself.
 boolean figureNextState(Cell north, Cell south, Cell east, Cell west, Cell northeast, Cell northwest, Cell southeast, Cell southwest)
          figure the next state.
 boolean isAlive()
          Return true if this cell or any subcells are alive.
 Direction isDisruptiveTo()
          Returns a Direction indicated the directions of the cells that have changed state.
 void redraw(Graphics g, Rectangle here, boolean drawAll)
          Redraw yourself in the indicated rectangle on the indicated Graphics object if ncessary.
 boolean transfer(Storable blob, Point upperLeft, boolean doLoad)
          This method is used internally to save or restore the state of a cell from a memento.
 boolean transition()
          Transition to the state computed by the most recent call to Cell.figureNextState(com.holub.life.Cell, com.holub.life.Cell, com.holub.life.Cell, com.holub.life.Cell, com.holub.life.Cell, com.holub.life.Cell, com.holub.life.Cell, com.holub.life.Cell)
 void userClicked(Point here, Rectangle surface)
          A user has clicked somewhere within you.
 int widthInCells()
          Return the specified width plus the current cell's width
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Resident

public Resident()
Method Detail

figureNextState

public boolean figureNextState(Cell north,
                               Cell south,
                               Cell east,
                               Cell west,
                               Cell northeast,
                               Cell northwest,
                               Cell southeast,
                               Cell southwest)
figure the next state.

Specified by:
figureNextState in interface Cell
Returns:
true if the cell is not stable (will change state on the next transition().

edge

public Cell edge(int row,
                 int column)
This cell is monetary, so it's at every edge of itself. It's an internal error for any position except for (0,0) to be requsted since the width is 1.

Specified by:
edge in interface Cell
Parameters:
row - The requested row. Must be on the edge of the block.
column - The requested column. Must be on the edge of the block.
Returns:
true if the the state changed.

transition

public boolean transition()
Description copied from interface: Cell
Transition to the state computed by the most recent call to Cell.figureNextState(com.holub.life.Cell, com.holub.life.Cell, com.holub.life.Cell, com.holub.life.Cell, com.holub.life.Cell, com.holub.life.Cell, com.holub.life.Cell, com.holub.life.Cell)

Specified by:
transition in interface Cell
Returns:
true if a changed of state happened during the transition.

redraw

public void redraw(Graphics g,
                   Rectangle here,
                   boolean drawAll)
Description copied from interface: Cell
Redraw yourself in the indicated rectangle on the indicated Graphics object if ncessary. This method is meant for a conditional redraw, where some of the cells might not be refreshed (if they haven't changed state, for example).

Specified by:
redraw in interface Cell
Parameters:
g - redraw using this graphics,
here - a rectangle that describes the bounds of the current cell.
drawAll - if true, draw an entire compound cell; otherwise, draw only the subcells that need to be redrawn.

userClicked

public void userClicked(Point here,
                        Rectangle surface)
Description copied from interface: Cell
A user has clicked somewhere within you.

Specified by:
userClicked in interface Cell
Parameters:
here - The position of the click relative to the bounding rectangle of the current Cell.

clear

public void clear()
Description copied from interface: Cell
Set the cell and all subcells into a "dead" state.

Specified by:
clear in interface Cell

isAlive

public boolean isAlive()
Description copied from interface: Cell
Return true if this cell or any subcells are alive.

Specified by:
isAlive in interface Cell

create

public Cell create()
Description copied from interface: Cell
Return a fresh (newly created) object identical to yourself in content.

Specified by:
create in interface Cell

widthInCells

public int widthInCells()
Description copied from interface: Cell
Return the specified width plus the current cell's width

Specified by:
widthInCells in interface Cell

isDisruptiveTo

public Direction isDisruptiveTo()
Description copied from interface: Cell
Returns a Direction indicated the directions of the cells that have changed state.

Specified by:
isDisruptiveTo in interface Cell
Returns:
A Direction object that indicates the edge or edges on which a change has occured.

transfer

public boolean transfer(Storable blob,
                        Point upperLeft,
                        boolean doLoad)
Description copied from interface: Cell
This method is used internally to save or restore the state of a cell from a memento.

Specified by:
transfer in interface Cell
Returns:
true if this cell was modified by the transfer.

createMemento

public Storable createMemento()
Mementos must be created by Neighborhood objects. Throw an exception if anybody tries to do it here.

Specified by:
createMemento in interface Cell