All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class gerken.vehicles.VehicleScenario

java.lang.Object
   |
   +----gerken.vehicles.VehicleScenario

public class VehicleScenario
extends Object
implements Runnable

The VehicleScenario class implements the behavior that manages a vehicle simulation. It contains all simulation participants and maintains the general simulation parameters.

This software is provided on an as-is basis and is copyright Chris Gerken. The only rights granted to you are to enjoy and learn from this software.


Constructor Index

 o VehicleScenario(int, int, boolean)

Return a vehicle scenario that covers an area w pixels wide and h pixels high.

Method Index

 o addParticipant(SimulationParticipant)

Register a participant in the scenario.

 o getBackground()

Return the Color used to paint the SimulationWindow's background.

 o getCenterX()

Return the x coordinate of the center of the scenario's simulation area

 o getCenterY()

Return the y coordinate of the center of the scenario's simulation area

 o getClosestTo(Location)

Return the participant closest to the given Location.

 o getDisplayCoordinates(DisplayCoordinates)

Perform transformations on a DisplayCoordinates to get the corresponding Location.

 o getDisplayCoordinates(Location)

Perform transformations on a Location to get the DisplayCoordinates that correctly represent that point in a SimulatorWindow.

 o getHeight()

Return the height in pixels of the simulation area

 o getMargin()

Return the width in pixels of the space between the simulaiton border and the edge of the screen.

 o getParticipants()

Return a vector containing all of the registered participants for the scenario.

 o getRandomDirection()

Return a random direction

 o getRandomX()

Return a random x coordinate between 0.0 and the scenario's width inclusive

 o getRandomY()

Return a random y coordinate between 0.0 and the scenario's height inclusive

 o getSimulationParticipantsColored(Color)

Return a Vector containing all of the registered simulation participants with color c.

 o getWidth()

Return the width of the scenario simulation area.

 o getWrapsAround()

Return whether or not vehicles can "see" and "travel" over borders to the other side of the scenario simulation area.

 o go()

Begin continuous simulation.

 o halt()

Stop continuous simulation.

 o removeParticipant(SimulationParticipant)

Remove (unregister) a participant from the simulation.

 o run()

Begin simulation of this scenario on a new thread.

 o setColor(Color)

Set the current foreground color on the SimulationWIndows's Canvas.

 o setColorToBackground()

Convenience method to set the current forground color for the SimulationWindow's Canvas to that Canvas' background color.

 o start()

Put up a SimulationWindow for the scenario and display the initial positions of the scenario's registered participants.

 o step()

Perform a single step in the scenario's simulation.

 o verifyLocation(SimulationParticipant)

Check to see if the participant sits outside of the ScenarioBoundary.

Constructors

 o VehicleScenario
 public VehicleScenario(int w,
                        int h,
                        boolean a)

Return a vehicle scenario that covers an area w pixels wide and h pixels high. Boolean value a indicates whether participants can see and move across borders (by wraping around to the opposite border).

Parameters:
w - int
h - int

Methods

 o addParticipant
 public void addParticipant(SimulationParticipant participant)

Register a participant in the scenario.

Parameters:
participant - com.gerken.vehicles.SimulationParticipant
 o getBackground
 public Color getBackground()

Return the Color used to paint the SimulationWindow's background. This is useful for "erasing" a vehicle at its old positin before it is drawn in its new position.

 o getCenterX
 public double getCenterX()

Return the x coordinate of the center of the scenario's simulation area

Returns:
double
 o getCenterY
 public double getCenterY()

Return the y coordinate of the center of the scenario's simulation area

Returns:
double
 o getClosestTo
 public SimulationParticipant getClosestTo(Location l)

Return the participant closest to the given Location.

Parameters:
l - gerken.vehicles.Location
Returns:
gerken.vehicles.SimulationParticipant
 o getDisplayCoordinates
 public Location getDisplayCoordinates(DisplayCoordinates dc)

Perform transformations on a DisplayCoordinates to get the corresponding Location.

Parameters:
dc - gerken.vehicles.DisplayCoordinates
Returns:
gerken.vehicles.Location
 o getDisplayCoordinates
 public DisplayCoordinates getDisplayCoordinates(Location l)

Perform transformations on a Location to get the DisplayCoordinates that correctly represent that point in a SimulatorWindow.

Parameters:
l - gerken.vehicles.Location
Returns:
gerken.vehicles.DisplayCoordinates
 o getHeight
 public double getHeight()

Return the height in pixels of the simulation area

Returns:
int
 o getMargin
 public int getMargin()

Return the width in pixels of the space between the simulaiton border and the edge of the screen.

Returns:
int
 o getParticipants
 public Vector getParticipants()

Return a vector containing all of the registered participants for the scenario.

Parameters:
participant - com.gerken.vehicles.SimulationParticipant
 o getRandomDirection
 public double getRandomDirection()

Return a random direction

Returns:
double
 o getRandomX
 public double getRandomX()

Return a random x coordinate between 0.0 and the scenario's width inclusive

Returns:
double
 o getRandomY
 public double getRandomY()

Return a random y coordinate between 0.0 and the scenario's height inclusive

Returns:
double
 o getSimulationParticipantsColored
 public Vector getSimulationParticipantsColored(Color c)

Return a Vector containing all of the registered simulation participants with color c.

Parameters:
c - java.awt.Color
Returns:
java.util.Vector
 o getWidth
 public double getWidth()

Return the width of the scenario simulation area.

Returns:
int
 o getWrapsAround
 public boolean getWrapsAround()

Return whether or not vehicles can "see" and "travel" over borders to the other side of the scenario simulation area.

Returns:
boolean
 o go
 public void go()

Begin continuous simulation.

See Also:
halt
 o halt
 public void halt()

Stop continuous simulation.

See Also:
go
 o removeParticipant
 public void removeParticipant(SimulationParticipant participant)

Remove (unregister) a participant from the simulation. This is usually done when a participant has been rendered inactive.

Parameters:
participant - gerken.vehicles.SimulationParticipant
 o run
 public void run()

Begin simulation of this scenario on a new thread.

 o setColor
 public void setColor(Color value)

Set the current foreground color on the SimulationWIndows's Canvas.

Parameters:
value - java.awt.Color
 o setColorToBackground
 public void setColorToBackground()

Convenience method to set the current forground color for the SimulationWindow's Canvas to that Canvas' background color. This is usually used to "erase" a vehicle before drawing it in its new position.

 o start
 public void start()

Put up a SimulationWindow for the scenario and display the initial positions of the scenario's registered participants. It is expected that the scenario is ready to begin imulation when this method is called.

 o step
 public void step()

Perform a single step in the scenario's simulation.

 o verifyLocation
 public void verifyLocation(SimulationParticipant participant)

Check to see if the participant sits outside of the ScenarioBoundary. If so, take appropriate action for the setting of the wrapsAround property.

Parameters:
participant - gerken.vehicles.SimulationParticipant

All Packages  Class Hierarchy  This Package  Previous  Next  Index