/** * Method: makeMove() Usage: last step in act() of Critter * ------------------------------------------- Follower faces the same way target is and steps are * incremented, if target is null, it faces the direction it just moved in then calls Critters * makeMove to go to the new location @Postcondition: (1) <code>getLocation() == loc</code>. (2) * The state of all actors other than those at the old and new locations is unchanged. * * @param loc the location to move to */ public void makeMove(Location loc) { if (target != null) { setDirection(target.getDirection()); steps++; } else setDirection(getLocation().getDirectionToward(loc)); super.makeMove(loc); }
/** If the crab critter doesn't move, it randomly turns left or right. */ public void makeMove(Location loc) { if (loc.equals(getLocation())) { double r = Math.random(); int angle; if (r < 0.5) angle = Location.LEFT; else angle = Location.RIGHT; setDirection(getDirection() + angle); } else super.makeMove(loc); }
/** * Turns towards the new location as it moves. * * @param loc the new location. */ @Override public void makeMove(Location loc) { setDirection(getLocation().getDirectionToward(loc)); super.makeMove(loc); }
public void act() { super.act(); breed(); }