|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object becker.robots.Sim becker.robots.Thing
public class Thing
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.
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 |
---|
public Thing(City aCity, int aStreet, int anAvenue, Direction orientation, boolean canBeMoved, Icon anIcon)
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.public Thing(City aCity, int aStreet, int anAvenue)
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.public Thing(City aCity, int aStreet, int anAvenue, Direction orientation)
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.public Thing(Robot heldBy)
heldBy
- the robot that will hold the new thing in its backpack.Method Detail |
---|
public void setCanBeCarried(boolean canCarry)
canCarry
- true
if this thing can be carried; false
otherwise.public boolean canBeCarried()
public void setBlocksEntry(boolean north, boolean south, boolean east, boolean west)
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.public void setBlocksEntry(Direction aDir, boolean block)
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.public void setBlocksExit(boolean north, boolean south, boolean east, boolean west)
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.public void setBlocksExit(Direction aDir, boolean block)
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.public boolean blocksIntersectionEntry(Direction entryDir)
entryDir
- The direction from which the entry might be blocked.
One of {Direction
.NORTH, SOUTH, EAST, WEST}.
public boolean blocksIntersectionExit(Direction exitDir)
exitDir
- The direction in which the exit might be blocked.
One of {Direction
.NORTH, SOUTH, EAST, WEST}.
protected Intersection getIntersection()
getIntersection
in class Sim
protected void save(String indent, PrintWriter out)
indent
- the indentation, for formatting purposesout
- the output streampublic String toString()
toString
in class Sim
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |