Class Car

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

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

This class models a car in our scene.


Constructor Summary
Car(Director director, Road road, char direction, int width, int height, int speed, java.awt.Color color)
          Construct the Rectangle avatar for the Car given the Road it is on and the direction of travel.
 
Method Summary
 void addTo(uwcse.graphics.GWindow g)
          Add the elements of this display object to the graphics window.
 void advance()
          This method moves the car a little bit.
 boolean carIsOnRoad(Road roadToCheck)
          This method checks whether the Car is on a given Road by checking its upper left corner against the boundaries of the Road.
 Road getCrossRoad()
          This method checks the coordinates of all Roads (other than the one the Car is intended to be traveling on) to see if the Car also happens to be on one of those Roads.
 Road getCurrentRoad()
          Return the Road that the Car is currently traveling along.
 void removeFromWindow()
          Remove the elements of this display object from the graphics window.
 void speedUpIfInNewIntersection()
          This method asks getCrossRoad() if the Car is in any intersection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Car

public Car(Director director,
           Road road,
           char direction,
           int width,
           int height,
           int speed,
           java.awt.Color color)
Construct the Rectangle avatar for the Car given the Road it is on and the direction of travel.

Parameters:
director - the Director object that will need to be queried by the Car
road - the Road on which the car is to be traveling initially
direction - the initial cardinal direction of the car's travel ('N','E','S','W')
width - width of the car's Rectangle
height - height of the car's Rectangle
speed - number of pixels to move the Car per frame
color - color of the Car
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

advance

public void advance()
This method moves the car a little bit.


carIsOnRoad

public boolean carIsOnRoad(Road roadToCheck)
This method checks whether the Car is on a given Road by checking its upper left corner against the boundaries of the Road.

Parameters:
roadToCheck - the Road to be checked
Returns:
true if the upper left corner of the Car is within the boundaries of this Road, false otherwise

getCrossRoad

public Road getCrossRoad()
This method checks the coordinates of all Roads (other than the one the Car is intended to be traveling on) to see if the Car also happens to be on one of those Roads. If so, then the Car is (obviously) in an intersection with that Road, and we return it. If the Car is not in any intersection, the method returns the null value.

Returns:
the Road object in whose intersection the Car is currently sitting, or null if the Car is not in any intersection

speedUpIfInNewIntersection

public void speedUpIfInNewIntersection()
This method asks getCrossRoad() if the Car is in any intersection. If the Car is in an intersection, the Car doubles its speed. However, it only doubles its speed if this isn't the same intersection it was in the last time the Car checked.


getCurrentRoad

public Road getCurrentRoad()
Return the Road that the Car is currently traveling along.

Returns:
the Road object that the Car is currently traveling along