import java.awt.Color; import java.util.ArrayList; import java.util.Random; public class CircleFish extends Fish { private int movement = 1; public CircleFish(Environment env, Location loc) { super(env, loc); // TODO Auto-generated constructor stub } public CircleFish(Environment env, Location loc, Direction dir) { super(env, loc, dir); // TODO Auto-generated constructor stub } public CircleFish(Environment env, Location loc, Direction dir, Color col) { super(env, loc, dir, col); // TODO Auto-generated constructor stub } protected void move() { // Find a location to move to. Debug.print("Fish " + toString() + " attempting to move. "); Location nextLoc = nextLocation(); // If the next location is different, move there. if (movement == 1) { // Move to new location. Location oldLoc = location(); changeLocation(nextLoc); // Update direction in case fish had to turn to move. changeDirection(direction().toRight()); } else if (location() == nextLoc) { changeDirection(direction().toRight()); } else changeLocation(nextLoc); } protected Location nextLocation() { Environment env = environment(); Location oneInFront = env.getNeighbor(location(), direction()); Location oneRight = env.getNeighbor(oneInFront, direction().toRight()); Debug.println(" Location in circle is empty? " + env.isEmpty(oneRight)); if (movement == 1) { movement = 0; if ( env.isEmpty(oneInFront) && env.isValid(oneInFront)) { return oneInFront; } } else if (movement == 0) { movement = 1; if ( env.isEmpty(oneRight) && env.isValid(oneRight)) { return oneRight; } } // Only get here if there isn't a valid location to move to. return location(); } }