// CSE 142 Lecture 21 // Static Members // This class represents a Chameleon. All Chameleons are the same color // and the color switches each move. They always forfeit in a fight, // stay in one place, and never eat. Some chameleons are displayed as // <:=)==(=- and some are displayed as -=)==(=:> import java.awt.*; // For Color import java.util.*; // For Random public class Chameleon extends Critter { private static int sharedMoveCount; private static Color sharedColor; private int moveCount; private static Random rand; private String display; public Chameleon() { if (rand == null) { rand = new Random(); } moveCount = sharedMoveCount; if (rand.nextBoolean()) { display = "<:=)==(=-"; } else { display = "-=)==(=:>"; } } public Direction getMove() { moveCount++; if (moveCount > sharedMoveCount) { sharedMoveCount++; sharedColor = new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)); } return Direction.CENTER; } public Color getColor() { return sharedColor; } public String toString() { return display; } }