becker.robots
Class Light

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

public abstract class Light
extends Thing

A light is a kind of thing that can be turned on to make it brighter and turned off to make it darker. Some lights can be moved (Flasher) while others can't (Streetlight).

The Light class itself is abstract meaning programmers cannot construct an instance of Light. It must be extended to create a class that can be instantiated. This class does define a common interface for all lights so that that any light may be turned on or off without knowing what specific kind of light it is (polymorphism).


Constructor Summary
Light(City aCity, int aStreet, int anAvenue)
          Construct a new light with the same default appearance as a Thing.
Light(City aCity, int aStreet, int anAvenue, Direction orientation, boolean canBeMoved, Icon anIcon)
          Construct a new light.
Light(Robot heldBy)
          Construct a new Light held by a robot.
 
Method Summary
 boolean isOn()
          Determine whether or not the light is turned on.
 void turnOff()
          Turn the light off.
 void turnOn()
          Turn the light on.
 
Methods inherited from class becker.robots.Thing
blocksIntersectionEntry, blocksIntersectionExit, canBeCarried, getIntersection, save, setBlocksEntry, setBlocksEntry, setBlocksExit, setBlocksExit, setCanBeCarried, toString
 
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

Light

public Light(City aCity,
             int aStreet,
             int anAvenue)
Construct a new light with the same default appearance as a Thing.

Parameters:
aCity - The city in which the light will exist.
aStreet - The light's initial street within the city.
anAvenue - The light's initial avenue within the city.

Light

public Light(City aCity,
             int aStreet,
             int anAvenue,
             Direction orientation,
             boolean canBeMoved,
             Icon anIcon)
Construct a new light.

Parameters:
aCity - The city in which the light will exist.
aStreet - The light's initial street within the city.
anAvenue - The light's initial avenue within the city.
orientation - The light's initial orientation. A streetlight, for instance, uses this to determine on which corner of the intersection it appears. One of {Direction.NORTH, EAST, SOUTH, WEST, NORTHWEST, NORTHEAST, SOUTHWEST, SOUTHEAST}.
canBeMoved - Specifies whether or not the light can be moved by a robot.
anIcon - The icon to use to display this light.

Light

public Light(Robot heldBy)
Construct a new Light held by a robot.

Parameters:
heldBy - the robot holding the light.
Method Detail

turnOn

public void turnOn()
Turn the light on.


turnOff

public void turnOff()
Turn the light off.


isOn

public boolean isOn()
Determine whether or not the light is turned on.

Returns:
true if the light is on; false otherwise.