/** * 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); }
/** * Method: getMoveLocations() Usage: 3rd step in act() of Critter ---------------------------- if * Follower has a target, Follower moves to the location opposite to the target's direction if * target is null, Follower roams like a generic Critter until a target is found @Postcondition: * The state of all actors is unchanged. * * @return a list of possible locations for the next move */ public ArrayList<Location> getMoveLocations() { ArrayList<Location> nextLoc = new ArrayList<Location>(); if (target != null) { Location next = target.getLocation().getAdjacentLocation(target.getDirection() + Location.HALF_CIRCLE); if (getGrid().isValid(next)) nextLoc.add(next); } else { for (Location l : super.getMoveLocations()) // for every empty adjacent loc if (getGrid().isValid(l)) // if it's also valid nextLoc.add(l); // add it to list of possible locs } return nextLoc; }