// This defines a simple class of critters that infect whenever they can and // otherwise just spin around, looking for critters to infect. // Its color is red. // Its toString is totalNum / myNum, where totalNum is the total number of // CountingFlyTraps that have been created, and myNum which is the individual // CountingFlyTrap's creation number (eg, 1 for it was the first made, 2 for // it was the second made, etc.) import java.awt.*; public class CountingFlyTrap extends Critter{ // NOTE: Static fields are an advanced feature which is ONLY to be used in the // creative Huskies. You are NOT required to use them anywhere. // Since this is a static field, it is one number shared by all CountingFlyTraps, // Since they all share this one value and each one adds one to it when it is created, // this holds the total number of CountingFlyTrap's made private static int totalNum; // This is a normal, non-static field, which means that each CountingFlyTrap has // its own value here. private int myNum; public CountingFlyTrap(){ // update the total number of CountingFlyTraps made totalNum++; // If there have now been, say 5 CountingFlyTraps made (totalNum ==5), then // I want to say I am the 5th CountingFlyTrap. So I save the current value of // the shared totalNum into my individual myNum field. myNum = totalNum; } 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 myNum + "/" + totalNum; } }