// Marty Stepp, CSE 142, Autumn 2008 // // This class represents Cougar critters. // A Cougar is the dumbest of all animals. // It always eats, always pounces when fighting, // and moves back and forth in a west-twice, east-twice pattern. import java.awt.*; // for Color public class Cougar extends Critter { private int moves; // how many moves the cougar has made private boolean hasFought; // has the Cougar been in a fight before? // The cougar has initially made 0 moves and has not fought. public Cougar() { moves = 0; hasFought = false; } // Cougars are gluttons, so they always eat. public boolean eat() { return true; } // Cougars always pounce when in a fight. public Attack fight(String opponent) { hasFought = true; return Attack.POUNCE; } // Cougars are blue until they have been in a fight, and then red afterward. public Color getColor() { if (hasFought) { return Color.RED; } else { return Color.BLUE; } } // Cougars move west 2, east 2, then repeat. // // Possible directions: // NORTH (up), SOUTH (down), EAST (right), WEST (left), CENTER (stay still) // public Direction getMove() { moves++; if (moves > 4) { moves = 1; // start over } if (moves == 1 || moves == 2) { return Direction.WEST; } else { // moves == 3 || moves == 4 return Direction.EAST; } } // Cougars are drawn on the game as a "C". public String toString() { return "C"; } }