Class Creature

java.lang.Object
  extended by Creature

public class Creature
extends Object

This class represents one creature on the board. Each creature must remember its species, position, direction, and the world in which it is living.

In addition, the Creature must remember the next instruction out of its program to execute.

The creature is also repsonsible for making itself appear in the WorldMap. In fact, you should only update the WorldMap from inside the Creature class.


Constructor Summary
Creature(Species species, World<Creature> world, Position pos, int dir)
          Create a creature of the given species, with the indicated position and direction.
 
Method Summary
 int direction()
          Return the current direction of the creature.
static int leftFrom(int direction)
          Return the compass direction the is 90 degrees left of the one passed in.
static void main(String[] st)
          This main program reads in one species, creates one creature, and gives it twenty turns.
 Position position()
          Return the position of the creature.
static int rightFrom(int direction)
          Return the compass direction the is 90 degrees right of the one passed in.
 Species species()
          Return the species of the creature.
 void takeOneTurn()
          Execute steps from the Creature's program until a hop, left, right, or infect instruction is executed.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Creature

public Creature(Species species,
                World<Creature> world,
                Position pos,
                int dir)
Create a creature of the given species, with the indicated position and direction. Note that we also pass in the world-- remember this world, so that you can check what is in front of the creature and to update the board when the creature moves.

Method Detail

species

public Species species()
Return the species of the creature.


direction

public int direction()
Return the current direction of the creature.


position

public Position position()
Return the position of the creature.


takeOneTurn

public void takeOneTurn()
Execute steps from the Creature's program until a hop, left, right, or infect instruction is executed.


leftFrom

public static int leftFrom(int direction)
Return the compass direction the is 90 degrees left of the one passed in.


rightFrom

public static int rightFrom(int direction)
Return the compass direction the is 90 degrees right of the one passed in.


main

public static void main(String[] st)
This main program reads in one species, creates one creature, and gives it twenty turns.