/* CSE 142, Autumn 2007, Marty Stepp This class is an example of a Critter. A Cougar is a slow, stupid animal. It flashes between red and blue color randomly. Its movement is to go three steps west, 3 steps east, and repeat. */ import java.awt.*; import java.util.*; public class Cougar implements Critter { // counts the number of times this Cougar has moved private int moves; public Cougar() { moves = 0; // start out having made 0 moves } public boolean eat() { return false; } public int fight(String opponent) { return ROAR; } // randomly returns either red or blue color with equal probability public Color getColor() { Random randy = new Random(); int r = randy.nextInt(2); if (r == 0) { return Color.RED; } else { return Color.BLUE; } } // moves 3 squares west, 3 squares east, and then repeats public int getMove(CritterInfo info) { if (moves == 6) { moves = 0; // start over } moves++; if (moves <= 3) { return WEST; } else { return EAST; } } public String toString() { return "C"; } }