Class Insect

java.lang.Object
  extended byInsect
All Implemented Interfaces:
Critter

public class Insect
extends java.lang.Object
implements Critter

This class implements a basic critter that lives in BugWorld.


Constructor Summary
Insect()
          Initialize and remember the CritterInfo for this Critter.
 
Method Summary
 CritterInfo getCritterInfo()
          This method returns the CritterInfo object that is storing information about this Critter.
 CritterFace getFace(int w, int h)
          This method returns a CritterFace (a displayable collection of Shapes) that can be used to represent this Critter in a MatrixView.
 Critter reproduce()
          This method creates another object of the same type as this Critter.
 int[] selectNextCell(MatrixModel model, int[] curLoc)
          This method implements the logic of this Critter that decides where it wants to move to next.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Insect

public Insect()
Initialize and remember the CritterInfo for this Critter.

Method Detail

selectNextCell

public int[] selectNextCell(MatrixModel model,
                            int[] curLoc)
Description copied from interface: Critter
This method implements the logic of this Critter that decides where it wants to move to next. The MatrixModel is provided so that this Critter can ask the model about its neighbors, if it wants to use that information in making the decision.

Specified by:
selectNextCell in interface Critter
Parameters:
model - the MatrixModel that this Critter inhabits
curLoc - a 2-element int array containing the current cell location of this Critter. The row address is in element [0] and the column address is in element [1].
Returns:
a 2-element int array to hold the cell location this Critter would like to move to. The row address is in element [0] and the column address is in element [1].
See Also:
Critter.selectNextCell(MatrixModel, int[])

getFace

public CritterFace getFace(int w,
                           int h)
Description copied from interface: Critter
This method returns a CritterFace (a displayable collection of Shapes) that can be used to represent this Critter in a MatrixView. The width and height of the available space are provided so that the Shapes can be scaled to fit the space. It's also possible to create a different face depending on the amount of space available. For example, a very small space might just get a dot, but a larger space could get a small drawing.

Specified by:
getFace in interface Critter
Parameters:
w - the width in pixels of the space the Shapes will occupy on screen
h - the height in pixels of the space the Shapes will occupy on screen
Returns:
the CritterFace to display for this Critter
See Also:
Critter.getFace(int, int)

getCritterInfo

public CritterInfo getCritterInfo()
Description copied from interface: Critter
This method returns the CritterInfo object that is storing information about this Critter.

Specified by:
getCritterInfo in interface Critter
Returns:
an object that implements the CritterInfo interface and holds current information about the Critter
See Also:
Critter.getCritterInfo()

reproduce

public Critter reproduce()
Description copied from interface: Critter
This method creates another object of the same type as this Critter.

Specified by:
reproduce in interface Critter
Returns:
a new Critter object of the same type as this Critter
See Also:
Critter.reproduce()