becker.robots
Class Thing

java.lang.Object
  extended by becker.robots.Sim
      extended by becker.robots.Thing
Direct Known Subclasses:
Light, Wall

public class Thing
extends Sim

A Thing is something that can exist on an intersection. All things have a location (avenue and street). Some things can be picked up and moved by a robot (Flashers) while others cannot (Streetlights, Walls).

In addition to a location, all things have an orientation although it is common for the orientation to always have a default value. Examples where that is not the case is a wall where the orientation determines which exit or entry into an intersection is blocked and a streetlight where the orientation determines which corner of the intersection it occupies.

Author:
Byron Weber Becker

Constructor Summary
Thing(City aCity, int aStreet, int anAvenue)
          Construct a new Thing with a default appearance that can be carried.
Thing(City aCity, int aStreet, int anAvenue, Direction orientation)
          Construct a new Thing with a default appearance that can be carried, in the given orientation.
Thing(City aCity, int aStreet, int anAvenue, Direction orientation, boolean canBeMoved, Icon anIcon)
          Construct a new Thing with an appearance defined by anIcon.
Thing(Robot heldBy)
          Construct a new thing held by the given robot.
 
Method Summary
 boolean blocksIntersectionEntry(Direction entryDir)
          Does this Thing block the entry of this intersection from the given direction?
 boolean blocksIntersectionExit(Direction exitDir)
          Does this Thing block the exit of this intersection in the given direction?
 boolean canBeCarried()
          Can this thing be picked up, carried, and put down by a robot?
protected  Intersection getIntersection()
          Return a reference to this thing's intersection.
protected  void save(String indent, PrintWriter out)
          Save a representation of this intersection to an output stream.
 void setBlocksEntry(boolean north, boolean south, boolean east, boolean west)
          Set whether this thing blocks a robot's entry from the given directions.
 void setBlocksEntry(Direction aDir, boolean block)
          Set whether this thing blocks a robot's entry in the given direction.
 void setBlocksExit(boolean north, boolean south, boolean east, boolean west)
          Set whether this thing blocks a robot's exit in the given directions.
 void setBlocksExit(Direction aDir, boolean block)
          Set whether this thing blocks a robot's exit in the given direction.
 void setCanBeCarried(boolean canCarry)
          Set whether this thing can be picked up and carried by a robot.
 String toString()
          Print this object represented as a string.
 
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
 

Constructor Detail

Thing

public Thing(City aCity,
             int aStreet,
             int anAvenue,
             Direction orientation,
             boolean canBeMoved,
             Icon anIcon)
Construct a new Thing with an appearance defined by anIcon.

Parameters:
aCity - The city where the thing exists.
aStreet - The street within the city where the Thing will be placed.
anAvenue - The avenue within the city where the Thing will be placed.
orientation - The orientation the thing will have in the city. One of {Direction.NORTH, EAST, SOUTH, WEST, SOUTHEAST, NORTHEAST, SOUTHWEST, NORTHWEST}, although subclasses may provide further restrictions.
canBeMoved - True if this Thing can be picked up and moved by a Robot; false otherwise.
anIcon - The icon to use to display this thing.

Thing

public Thing(City aCity,
             int aStreet,
             int anAvenue)
Construct a new Thing with a default appearance that can be carried.

Parameters:
aCity - The city where the thing exists.
aStreet - The street within the city where the Thing will be placed.
anAvenue - The avenue within the city where the Thing will be placed.

Thing

public Thing(City aCity,
             int aStreet,
             int anAvenue,
             Direction orientation)
Construct a new Thing with a default appearance that can be carried, in the given orientation.

Parameters:
aCity - The city where the thing exists.
aStreet - The street within the city where the Thing will be placed.
anAvenue - The avenue within the city where the Thing will be placed.
orientation - The orientation the thing will have in the city. One of {Direction.NORTH, EAST, SOUTH, WEST, SOUTHEAST, NORTHEAST, SOUTHWEST, NORTHWEST}, although subclasses may provide further restrictions.

Thing

public Thing(Robot heldBy)
Construct a new thing held by the given robot.

Parameters:
heldBy - the robot that will hold the new thing in its backpack.
Method Detail

setCanBeCarried

public void setCanBeCarried(boolean canCarry)
Set whether this thing can be picked up and carried by a robot.

Parameters:
canCarry - true if this thing can be carried; false otherwise.

canBeCarried

public boolean canBeCarried()
Can this thing be picked up, carried, and put down by a robot?

Returns:
True if this thing can be carried; false otherwise.

setBlocksEntry

public void setBlocksEntry(boolean north,
                           boolean south,
                           boolean east,
                           boolean west)
Set whether this thing blocks a robot's entry from the given directions.

Parameters:
north - true if this thing blocks a robot from entering from the NORTH; false otherwise.
south - true if this thing blocks a robot from entering from the SOUTH; false otherwise.
east - true if this thing blocks a robot from entering from the EAST; false otherwise.
west - true if this thing blocks a robot from entering from the WEST; false otherwise.

setBlocksEntry

public void setBlocksEntry(Direction aDir,
                           boolean block)
Set whether this thing blocks a robot's entry in the given direction.

Parameters:
aDir - The direction to block in which to block a robot's exit.
block - true if this thing blocks a robot from entering from the given direction; false otherwise.

setBlocksExit

public void setBlocksExit(boolean north,
                          boolean south,
                          boolean east,
                          boolean west)
Set whether this thing blocks a robot's exit in the given directions.

Parameters:
north - true if this thing blocks a robot from exiting to the NORTH; false otherwise.
south - true if this thing blocks a robot from exiting to the SOUTH; false otherwise.
east - true if this thing blocks a robot from exiting to the EAST; false otherwise.
west - true if this thing blocks a robot from exiting to the WEST; false otherwise.

setBlocksExit

public void setBlocksExit(Direction aDir,
                          boolean block)
Set whether this thing blocks a robot's exit in the given direction.

Parameters:
aDir - The direction to block in which to block a robot's exit.
block - true if this thing blocks a robot from exiting in the given direction; false otherwise.

blocksIntersectionEntry

public boolean blocksIntersectionEntry(Direction entryDir)
Does this Thing block the entry of this intersection from the given direction?

Parameters:
entryDir - The direction from which the entry might be blocked. One of {Direction.NORTH, SOUTH, EAST, WEST}.
Returns:
True if entry from the given direction is blocked by this Thing, false otherwise.

blocksIntersectionExit

public boolean blocksIntersectionExit(Direction exitDir)
Does this Thing block the exit of this intersection in the given direction?

Parameters:
exitDir - The direction in which the exit might be blocked. One of {Direction.NORTH, SOUTH, EAST, WEST}.
Returns:
True if the exit in the given direction is blocked by this Thing, false otherwise.

getIntersection

protected Intersection getIntersection()
Return a reference to this thing's intersection. If the thing is being carried by a robot, this thing's intersection is the same as the robot's intersection.

Specified by:
getIntersection in class Sim
Returns:
This thing's intersection.

save

protected void save(String indent,
                    PrintWriter out)
Save a representation of this intersection to an output stream.

Parameters:
indent - the indentation, for formatting purposes
out - the output stream

toString

public String toString()
Print this object represented as a string.

Overrides:
toString in class Sim