/* CSE 142, Autumn 2007, Marty Stepp We wrote this critter in this week's section. Rabbits move in a "hopping" pattern, going up-down and then right. */ import java.awt.*; public class Rabbit implements Critter { private int moves; private boolean hungry; public Rabbit() { moves = 0; hungry = false; } public boolean eat() { hungry = !hungry; // reverse the boolean value return hungry; } public int fight(String opponent) { if (opponent.equals("L")) { // a Lion return SCRATCH; } else { return ROAR; } } public Color getColor() { return Color.WHITE; } public int getMove(CritterInfo info) { moves++; if (moves > 6) { moves = 1; // start over } if (moves <= 2) { // 1st or 2nd move return NORTH; } else if (moves <= 4) { // 3rd or 4th move return SOUTH; } else { // 5th or 6th move return EAST; } } public String toString() { return "V"; } }