// CSE 142, Summer 2008 (Helene Martin) // The Rabbit, from the section handout, hops. // We modified it to have a getHopHeight() method which could be overridden by subclasses. import java.awt.*; public class Rabbit extends Critter { private int moves; private boolean hungry; public Rabbit() { moves = 0; hungry = false; } public boolean eat() { // reverse the boolean value hungry = !hungry; return hungry; } public Attack fight(String opponent) { if (opponent.equals("L")) { // a Lion return Attack.SCRATCH; } else { return Attack.ROAR; } } public Color getColor() { return Color.DARK_GRAY; } // Hop: N N S S E E ... public Direction getMove() { moves++; if (moves > getHopHeight() * 3) { moves = 1; // start over } if (moves <= getHopHeight()) { // 1st or 2nd move return Direction.NORTH; } else if (moves <= getHopHeight() * 2) { // 3rd or 4th return Direction.SOUTH; } else { // 5th or 6th return Direction.EAST; } } public int getHopHeight() { return 2; } // Bunny ears public String toString() { return "V"; } }