becker.robots
Class RobotSE

java.lang.Object
  extended by becker.robots.Sim
      extended by becker.robots.Robot
          extended by becker.robots.RobotSE
All Implemented Interfaces:
IColor, ILabel

public class RobotSE
extends Robot

A new kind of robot with extended capabilities such as turnAround, and turnRight. RobotSE also makes public a number of protected methods in Robot.

Author:
Byron Weber Becker

Constructor Summary
RobotSE(City theCity, int street, int avenue, Direction dir)
          Construct a new RobotSE with nothing in its backpack.
RobotSE(City theCity, int street, int avenue, Direction dir, int numThings)
          Construct a new RobotSE.
 
Method Summary
 int countThingsInBackpack(IPredicate pred)
          How many of a specific kind of thing are in this robot's backpack?
 boolean isBesideThing(IPredicate kindOfThing)
          Determine whether this robot is on the same intersection as one or more instances of the specified kind of thing.
 boolean isFacingEast()
          Determine whether the robot is facing east.
 boolean isFacingNorth()
          Determine whether the robot is facing north.
 boolean isFacingSouth()
          Determine whether the robot is facing south.
 boolean isFacingWest()
          Determine whether the robot is facing west.
 void move(int howFar)
          Move the given distance.
 void pickAllThings()
          Pick all the moveable things from the current intersection.
 void pickAllThings(IPredicate kindOfThing)
          Pick all of the specified kind of things from the current intersection.
 void pickThing(IPredicate kindOfThing)
          Attempt to pick up a particular kind of thing from the intersection this robot currently occupies.
 void pickThing(Thing theThing)
          Attempt to pick up a particular thing from the intersection this robot currently occupies.
 void putAllThings()
          Put all the things in this robot's backpack down on the current intersection.
 void putAllThings(IPredicate kindOfThing)
          Put all of the specified kind of things from the robot's backpack down on the current intersection.
 void putThing(IPredicate kindOfThing)
          Attempt to take a particular kind of thing out of this robot's backpack and put it on the intersection currently occupied by this robot.
 void putThing(Thing theThing)
          Attempt to put down a particular thing on the intersection this robot currently occupies.
 void save(String indent, PrintWriter out)
          Save a representation of this robot to an output stream.
 void turnAround()
          Turn the robot around so it faces the opposite direction.
 void turnLeft(int numTimes)
          Turn left the given number of times.
 void turnRight()
          Turn the robot 90 degrees to the right.
 void turnRight(int numTimes)
          Turn right the given number of times.
 
Methods inherited from class becker.robots.Robot
breakRobot, canPickThing, countThingsInBackpack, examineLights, examineRobots, examineThings, examineThings, frontIsClear, getAvenue, getDirection, getIntersection, getLabel, getSpeed, getStreet, getTransparency, makeThing, move, pickThing, putThing, setLabel, setSpeed, setTransparency, toString, turnLeft
 
Methods inherited from class becker.robots.Sim
getCity, getColor, getIcon, keyTyped, notifyObservers, notifyObservers, setColor, setIcon
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface becker.robots.IColor
getColor, setColor
 

Constructor Detail

RobotSE

public RobotSE(City theCity,
               int street,
               int avenue,
               Direction dir,
               int numThings)
Construct a new RobotSE.

Parameters:
theCity - the city in which the robot will be located.
street - the robot's initial street
avenue - the robot's initial avenue
dir - the robot's initial direction
numThings - the number of things initially in the robot's backpack

RobotSE

public RobotSE(City theCity,
               int street,
               int avenue,
               Direction dir)
Construct a new RobotSE with nothing in its backpack.

Parameters:
theCity - the city in which the robot will be located.
street - the robot's initial street
avenue - the robot's initial avenue
dir - the robot's initial direction
Method Detail

turnAround

public void turnAround()
Turn the robot around so it faces the opposite direction.


turnRight

public void turnRight()
Turn the robot 90 degrees to the right. This invokes a package access method in Robot to really turn the robot right rather than left three times.


turnRight

public void turnRight(int numTimes)
Turn right the given number of times.

Parameters:
numTimes - how many times to turn right. Must be >= 0.

move

public void move(int howFar)
Move the given distance.

Parameters:
howFar - how far to move. Must be >= 0.

turnLeft

public void turnLeft(int numTimes)
Turn left the given number of times.

Parameters:
numTimes - how many times to turn left. Must be >= 0.

pickAllThings

public void pickAllThings()
Pick all the moveable things from the current intersection.


pickAllThings

public void pickAllThings(IPredicate kindOfThing)
Pick all of the specified kind of things from the current intersection.

Parameters:
kindOfThing - The kind of things to pick up

putAllThings

public void putAllThings()
Put all the things in this robot's backpack down on the current intersection.


putAllThings

public void putAllThings(IPredicate kindOfThing)
Put all of the specified kind of things from the robot's backpack down on the current intersection.

Parameters:
kindOfThing - The kind of things to put down

isFacingNorth

public boolean isFacingNorth()
Determine whether the robot is facing north.

Returns:
true if the robot is facing north; false otherwise.

isFacingEast

public boolean isFacingEast()
Determine whether the robot is facing east.

Returns:
true if the robot is facing east; false otherwise.

isFacingSouth

public boolean isFacingSouth()
Determine whether the robot is facing south.

Returns:
true if the robot is facing south; false otherwise.

isFacingWest

public boolean isFacingWest()
Determine whether the robot is facing west.

Returns:
true if the robot is facing west; false otherwise.

countThingsInBackpack

public int countThingsInBackpack(IPredicate pred)
Description copied from class: Robot
How many of a specific kind of thing are in this robot's backpack?

Overrides:
countThingsInBackpack in class Robot
Parameters:
pred - The kind of thing to count.
Returns:
The number of things of the given kind.

isBesideThing

public boolean isBesideThing(IPredicate kindOfThing)
Description copied from class: Robot
Determine whether this robot is on the same intersection as one or more instances of the specified kind of thing.

Overrides:
isBesideThing in class Robot
Parameters:
kindOfThing - A predicate indicating what kind of thing should be looked for on the current intersection.
Returns:
True if there is a movable thing on the same intersection as the robot; false otherwise.

pickThing

public void pickThing(IPredicate kindOfThing)
Description copied from class: Robot
Attempt to pick up a particular kind of thing from the intersection this robot currently occupies. If nothing matches the kind of thing specified the robot will break. It is possible to specify things such as walls which cannot be moved. This, too, causes the robot to break. A broken robot will not respond to further commands.

Overrides:
pickThing in class Robot
Parameters:
kindOfThing - A predicate indicating what kind of thing should be picked up.
See Also:
Robot.pickThing(), Robot.pickThing(Thing)

pickThing

public void pickThing(Thing theThing)
Description copied from class: Robot
Attempt to pick up a particular thing from the intersection this robot currently occupies. If the thing does not exist on the current intersection or if the thing cannot be moved the robot will break, refusing to respond to further commands.

Overrides:
pickThing in class Robot
Parameters:
theThing - The thing to pick up.
See Also:
Robot.pickThing(), Robot.pickThing(IPredicate)

putThing

public void putThing(IPredicate kindOfThing)
Description copied from class: Robot
Attempt to take a particular kind of thing out of this robot's backpack and put it on the intersection currently occupied by this robot. If the backpack is already empty the robot will break and will no longer respond to commands.

Overrides:
putThing in class Robot
Parameters:
kindOfThing - A predicate indicating what kind of thing should be put down.
See Also:
Robot.putThing(), Robot.putThing(Thing)

putThing

public void putThing(Thing theThing)
Description copied from class: Robot
Attempt to put down a particular thing on the intersection this robot currently occupies. If the thing does not exist in the robot's backpact, the robot will break, refusing to respond to further commands.

Overrides:
putThing in class Robot
Parameters:
theThing - The thing to put down.
See Also:
Robot.putThing(), Robot.putThing(IPredicate)

save

public void save(String indent,
                 PrintWriter out)
Description copied from class: Robot
Save a representation of this robot to an output stream.

Overrides:
save in class Robot
Parameters:
indent - A string of blanks, for formatting purposes.
out - The output stream.