// Bee behavior: // constructor: Bee() // getColor: alternate between Color.YELLOW (starting with yellow) and Color.BLACK // every time it turns // toString: when created, randomly choose a path length between 1 and 10 and // display as that length // getMove: infect if an enemy is in front // otherwise if a wall is in front or the bee has moved at least as many steps // as the path length, turn right // otherwise hop import java.util.*; import java.awt.*; public class Bee extends Critter { private int pathLength; private int steps; private boolean isYellow; public Bee() { Random rand = new Random(); pathLength = rand.nextInt(10) + 1; steps = -1; isYellow = true; } public Color getColor() { if (isYellow) { return Color.YELLOW; } else { return Color.BLACK; } } public String toString() { return "" + pathLength; } public Action getMove(CritterInfo info) { steps++; if (info.getFront() == Neighbor.OTHER) { return Action.INFECT; } else if (info.getFront() == Neighbor.WALL || steps >= pathLength) { steps = -1; isYellow = !isYellow; return Action.RIGHT; } else { return Action.HOP; } } }