Class City

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

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

This class models all of the stationary objects in our scene.


Constructor Summary
City(Director director, int ewRoads, int nsRoads, int windowHeight, int windowWidth)
          Create a new City object with the specified number of East-West and North-South Roads, keeping in mind the space limitations of the provided GWindow dimensions.
 
Method Summary
 void addTo(uwcse.graphics.GWindow g)
          Add the elements of this display object to the graphics window.
 Road getEWRoad(int number)
          Retrieve the Road in the specified position in the East-West roadList.
 Road getNSRoad(int number)
          Retrieve the Road in the specified position in the North-South roadList.
 int getNumberOfEWRoads()
          Return the number of East-West roads.
 int getNumberOfNSRoads()
          Return the number of North-South roads.
 Road getRoadAboutToIntersect(Car car)
          Scan all of the Roads lying perpendicular to the given Car's path to see if the Car will be at or inside any of those intersections at the end of its next movement.
 TrafficLight getTrafficLightAtIntersectionOf(Road road1, Road road2)
          Return the TrafficLight object that exists at this intersection, or null if no light at that intersection can be found (perhaps because the intersection does not exist).
 void removeFromWindow()
          Remove the elements of this display object from the graphics window.
 void tick()
          Tell each TrafficLight in the City to count one clock tick.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

City

public City(Director director,
            int ewRoads,
            int nsRoads,
            int windowHeight,
            int windowWidth)
Create a new City object with the specified number of East-West and North-South Roads, keeping in mind the space limitations of the provided GWindow dimensions.

Parameters:
director - the Director object, which must be referenced to access the Cars
ewRoads - the integer number of East-West Roads in the City
nsRoads - the integer number of North-South Roads in the City
windowHeight - the integer height of the GWindow
windowWidth - the integer width of the GWindow
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

getEWRoad

public Road getEWRoad(int number)
Retrieve the Road in the specified position in the East-West roadList.

Parameters:
number - the integer index of the desired element in the Road list
Returns:
the desire Road object or null if there is no such Road

getNSRoad

public Road getNSRoad(int number)
Retrieve the Road in the specified position in the North-South roadList.

Parameters:
number - the integer index of the desired element in the Road list
Returns:
the desire Road object or null if there is no such Road

getNumberOfEWRoads

public int getNumberOfEWRoads()
Return the number of East-West roads.

Returns:
the integer number of East-West Road objects in the City

getNumberOfNSRoads

public int getNumberOfNSRoads()
Return the number of North-South roads.

Returns:
the integer number of North-South Road objects in the City

getTrafficLightAtIntersectionOf

public TrafficLight getTrafficLightAtIntersectionOf(Road road1,
                                                    Road road2)
Return the TrafficLight object that exists at this intersection, or null if no light at that intersection can be found (perhaps because the intersection does not exist).

Parameters:
road1 - one of the roads making up the intersection
road2 - the other road making up the intersection
Returns:
the TrafficLight object at this intersection or null if it does not exist

tick

public void tick()
Tell each TrafficLight in the City to count one clock tick.


getRoadAboutToIntersect

public Road getRoadAboutToIntersect(Car car)
Scan all of the Roads lying perpendicular to the given Car's path to see if the Car will be at or inside any of those intersections at the end of its next movement. If such a Road is found, it is returned. If not, null is returned.

Parameters:
car - the Car object being tested for near-intersection with the Roads
Returns:
the Road about to be intersected by the Car, if such a Road exists; if not, null