Projects Page‎ > ‎

Proj9 Critters


CritterZip.zip
(make sure to 'extract all')



In summary:
Critter Details
---------------
getMove returns one of:
Action.HOP, Action.LEFT, Action.RIGHT, Action.INFECT.

There are methods for finding out what kind of critters are around a critter one of:
   getFront(), getBack(), getLeft(), getRight()
That return:
   Neighbor.WALL, Neighbor.EMPTY, Neighbor.SAME, Neighbor.OTHER

There is a method getDirection() to find out what direction a critter is facing:
   Direction.NORTH, Direction.SOUTH, Direction.EAST, Direction.WEST

A short example program
public class FlyTrap extends Critter {
    public String toString() {
        return "T";
    }
    public Action getMove(CritterInfo info) {
        if (info.getFront() == Neighbor.OTHER) {
            return Action.INFECT;
        } else {
            return Action.LEFT;
        }
    }
    public Color getColor() {
        return Color.RED;
    }
}





Comments