Class TrafficLight

java.lang.Object
  |
  +--TrafficLight
All Implemented Interfaces:
uwcse.animation.Prop

public class TrafficLight
extends java.lang.Object
implements uwcse.animation.Prop


Constructor Summary
TrafficLight(Director director, Road ewRoad, Road nsRoad, int timeLimit)
          Create a new TrafficLight object with 4 lamps, one facing each cardinal direction, surrounding the center of an intersection.
 
Method Summary
 void addTo(uwcse.graphics.GWindow g)
          Add the elements of this display object to the graphics window.
 java.awt.Color getEastColor()
          Return the color of the east-facing lamp.
 Road getEWRoad()
          Return the East-West road running under this light.
 java.awt.Color getNorthColor()
          Return the color of the north-facing lamp.
 Road getNSRoad()
          Return the North-South road running under this light.
 java.awt.Color getSouthColor()
          Return the color of the south-facing lamp.
 java.awt.Color getWestColor()
          Return the color of the west-facing lamp.
 void removeFromWindow()
          Remove the elements of this display object from the graphics window.
 void tick()
          Count off a clock tick for this TrafficLight.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TrafficLight

public TrafficLight(Director director,
                    Road ewRoad,
                    Road nsRoad,
                    int timeLimit)
Create a new TrafficLight object with 4 lamps, one facing each cardinal direction, surrounding the center of an intersection. A TrafficLight records and distinguishes between the East-West Road and the North-South Road that comprise its intersection. A TrafficLight also maintains a time limit of the number of ticks until the light should change.

Parameters:
director - the Director object which must be queried for Car information
ewRoad - the East-West Road passing under this light
nsRoad - the North-South Road passing under this light
timeLimit - the integer timeout value governing the frequency of light changes
Method Detail

addTo

public void addTo(uwcse.graphics.GWindow g)
Add the elements of this display object to the graphics window.

Specified by:
addTo in interface uwcse.animation.Prop
Parameters:
g - the graphics window to use

removeFromWindow

public void removeFromWindow()
Remove the elements of this display object from the graphics window.

Specified by:
removeFromWindow in interface uwcse.animation.Prop

tick

public void tick()
Count off a clock tick for this TrafficLight. If the clock reaches the preset timeout value, change the light's status and reset the timer to zero, but only if there are no Cars currently in the intersection! If there is a Car in the intersection, the timer keeps going past the timeout.


getNorthColor

public java.awt.Color getNorthColor()
Return the color of the north-facing lamp.

Returns:
the Color object for the north lamp

getEastColor

public java.awt.Color getEastColor()
Return the color of the east-facing lamp.

Returns:
the Color object for the east lamp

getSouthColor

public java.awt.Color getSouthColor()
Return the color of the south-facing lamp.

Returns:
the Color object for the south lamp

getWestColor

public java.awt.Color getWestColor()
Return the color of the west-facing lamp.

Returns:
the Color object for the west lamp

getEWRoad

public Road getEWRoad()
Return the East-West road running under this light.

Returns:
the east-west Road of this intersection

getNSRoad

public Road getNSRoad()
Return the North-South road running under this light.

Returns:
the north-south Road of this intersection