java-projects/critters/FlyTrap.java

23 lines
581 B
Java
Raw Normal View History

// This defines a simple class of critters that infect whenever they can and
// otherwise just spin around, looking for critters to infect. This simple
// strategy turns out to be surpisingly successful.
import java.awt.*;
public class FlyTrap extends Critter {
public Action getMove(CritterInfo info) {
if (info.getFront() == Neighbor.OTHER) {
return Action.INFECT;
} else {
return Action.LEFT;
}
}
public Color getColor() {
return Color.RED;
}
public String toString() {
return "T";
}
}