Ejemplo n.º 1
0
 /**
  * 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);
 }
Ejemplo n.º 2
0
 /** 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);
 }
Ejemplo n.º 3
0
 /**
  * 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);
 }
Ejemplo n.º 4
0
 public void act() {
   super.act();
   breed();
 }