public static class Roads.TrafficLight extends Roads
AbstractTile
class, represents a
traffic light.Roads.Bow, Roads.Cross, Roads.Priority, Roads.Road, Roads.Stop, Roads.TrafficLight, Roads.Zebra
Modifier and Type | Field and Description |
---|---|
static int |
GAP_TIME
Constant used in order to determine the time line in
Semaphore . |
static int |
GREEN_INDEX
Constant used for the state of the traffic light's colour.
|
static int |
RED_INDEX
Constant used for the state of the traffic light's colour.
|
static int |
YELLOW_INDEX
Constant used for the state of the traffic light's colour.
|
static int |
YELLOW_TIME
Constant used in order to determine the time line in
Semaphore . |
Constructor and Description |
---|
Roads.TrafficLight(java.awt.Image[] sprites,
Coordinates position,
Direction[] way)
Constructor of
Roads.TrafficLight class, calls the constructor af
the super-class Roads , assigns the default state 2 (RED) and
the type of the tile to TRAFFIC_LIGHT of the TileType
enum. |
Modifier and Type | Method and Description |
---|---|
int |
getColour()
Returns the current state of the traffic light.
|
java.lang.Integer |
getGreenTime()
Returns the time given to the traffic light for the green time's
state.
|
int |
getPriority()
Returns the turn of the traffic light inside the cross.
|
java.awt.Image |
getSprite()
Gets the sprite related to the actual colour.
|
void |
setColour(int colour)
Sets the current state of the traffic light.
|
void |
setGreenTime(java.lang.Integer time)
Sets the time given to the traffic light for its green time's state.
|
void |
setPriority(int priority)
Sets the turn of the traffic light inside the cross in which is
involved.
|
void |
setSprite(java.awt.Image sprite,
int colour)
Sets a custom image for the related colour.
|
java.lang.String |
toString()
Returns the string indicating the current state of the traffic light.
|
getPosition, getPossibleWays, getType, setPosition, setPosition, setSprite
public static final int GAP_TIME
Semaphore
.public static final int YELLOW_TIME
Semaphore
.public static final int GREEN_INDEX
public static final int YELLOW_INDEX
public static final int RED_INDEX
public Roads.TrafficLight(java.awt.Image[] sprites, Coordinates position, Direction[] way) throws java.io.IOException
Roads.TrafficLight
class, calls the constructor af
the super-class Roads
, assigns the default state 2 (RED) and
the type of the tile to TRAFFIC_LIGHT
of the TileType
enum.sprites
- the images used to portray the tile in its different states [Green,Yellow,Red]position
- position expressed in Coordinates
way
- array of the possible ways expressed in Boolean[]java.io.IOException
- if the application couldn't retrieve imagespublic java.lang.Integer getGreenTime()
public void setGreenTime(java.lang.Integer time)
Notes: leaves the default value if the time passed as parameter is less/equal to 0 or higher than 20 (this implementation prevents a crash of the application, used temporary in the 'beta' version).
time
- the time given for the green time's statepublic int getPriority()
public void setPriority(int priority) throws java.lang.IllegalArgumentException
priority
- the turn of the traffic lightjava.lang.IllegalArgumentException
- if the value is less or equal than 0public int getColour()
public void setColour(int colour) throws java.lang.IllegalArgumentException
colour
- the new current state of the traffic lightjava.lang.IllegalArgumentException
- if the value passed as parameter is not in the rangepublic void setSprite(java.awt.Image sprite, int colour)
sprite
- the sprite to be setted as default imagecolour
- the colour to which the sprite will relatepublic java.awt.Image getSprite()
getSprite
in interface ITile
getSprite
in class AbstractTile
public java.lang.String toString()
toString
in class AbstractTile