/* CSE 142, Autumn 2007, Marty Stepp This class is an example of a Critter. A Tigger's movement behavior is the following: 1 step NORTH, 1 step SOUTH 2 steps NORTH, 2 steps SOUTH 3 steps NORTH, 3 steps NORTH 4 steps NORTH, 4 steps SOUTH ... */ import java.awt.*; public class Tigger implements Critter { // fields are good for: // - remembering things (values) // - counting things private int moves; // how many moves the Tigger has made private int bounceHeight; // how high the Tigger is bouncing this time public Tigger() { moves = 0; // initially the Tigger has not made any bounceHeight = 1; // moves and his bounce height is 1 } public boolean eat() { return true; // Tiggers are always hungry } public int fight(String opponent) { return POUNCE; // 'cause POUNCin is what Tiggers do best! } public Color getColor() { return Color.ORANGE; } public int getMove(CritterInfo info) { moves++; // System.out.println("This is my " + moves + "th move"); if (moves <= bounceHeight) { return NORTH; // I am on the way up } else if (moves <= 2 * bounceHeight) { return SOUTH; // I am on the way down } else { bounceHeight++; // I have reached the bottom of my bounce moves = 1; return NORTH; } } public String toString() { if (moves <= bounceHeight) { return "K"; // on the way up } else { return "k"; // on the way down } } }