|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--alpiv.trucks.BlockSupport
|
+--alpiv.trucks.Road
Objects of this class represent sections of a road map. A road can be (b)locked for exclusive access by a (Truck)-Thread. It is also possible register a truck as traffic on the road, but only one truck at a time.
| Field Summary | |
static int |
AHEAD
|
static int |
DIRECTIONS
Constants for the directions of exits. |
static java.lang.String[] |
DIRNAMES
Names for the directions. |
static int |
EAST
|
static int |
GOAL
|
static int |
LEFT
Constants for direction changes. |
static int |
NORTH
|
static int |
NORTHEAST
|
static int |
NORTHWEST
|
static int |
NOWHERE
|
static int |
REGULAR
Constants for the road types. |
static int |
RIGHT
|
static int |
SOUTH
|
static int |
SOUTHEAST
|
static int |
SOUTHWEST
|
static int |
START
|
static int |
WEST
|
| Constructor Summary | |
Road(java.lang.String name,
alpiv.trucks.RoadObserver observer)
Convenience constructor with name and observer. |
|
Road(java.lang.String name,
alpiv.trucks.RoadObserver observer,
int type)
Convenience constructor with name, observer, and type. |
|
Road(java.lang.String name,
alpiv.trucks.RoadObserver observer,
int x,
int y,
int type)
Full constructor. |
|
| Method Summary | |
Road |
getExit(int direction)
Get the road reachable in the given direction. |
java.lang.String |
getName()
Get the name of the road object. |
alpiv.trucks.Truck |
getTraffic()
Get the current traffic on this road. |
int |
getType()
Get the type of the road object. |
int |
getX()
Get the X coordinate for map layout. |
int |
getY()
Get the Y coordinate for map layout. |
static int |
nextDirection(int current,
int turn)
A helper method to calculate direction changes. |
static int |
oppositeDirection(int current)
A helper method to calculate the opposite of a direction. |
void |
setExit(int direction,
Road to)
Link this road to another one in the given direction. |
void |
setLocation(int x,
int y)
Set this roads location for layout purposes. |
void |
setTraffic(alpiv.trucks.Truck traffic)
Place or remove some traffic on the road. |
| Methods inherited from class alpiv.trucks.BlockSupport |
block, blocking, unblock |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int DIRECTIONS
public static final int NORTH
public static final int NORTHEAST
public static final int EAST
public static final int SOUTHEAST
public static final int SOUTH
public static final int SOUTHWEST
public static final int WEST
public static final int NORTHWEST
public static final java.lang.String[] DIRNAMES
public static final int LEFT
public static final int AHEAD
public static final int RIGHT
public static final int NOWHERE
public static final int REGULAR
public static final int START
public static final int GOAL
| Constructor Detail |
public Road(java.lang.String name,
alpiv.trucks.RoadObserver observer)
name - the name of the Road objectobserver - whom to notify of traffic changes
public Road(java.lang.String name,
alpiv.trucks.RoadObserver observer,
int type)
name - the name of the Road objectobserver - whom to notify of traffic changestype - what kind of road is this
public Road(java.lang.String name,
alpiv.trucks.RoadObserver observer,
int x,
int y,
int type)
name - the name of the Road objectobserver - whom to notify of traffic changesx - X coordinate for displaying this roady - Y coordinate for displaying this roadtype - what kind of road is this| Method Detail |
public static int nextDirection(int current,
int turn)
current - the current directionturn - the direction to move to
public static int oppositeDirection(int current)
current - the current direction
public int getType()
public java.lang.String getName()
public int getX()
public int getY()
public alpiv.trucks.Truck getTraffic()
public void setLocation(int x,
int y)
x - the X coordinate of this roady - the Y coordinate of this roadpublic void setTraffic(alpiv.trucks.Truck traffic)
traffic - the truck to place on this road, or null to clear it
public void setExit(int direction,
Road to)
direction - direction where to reach the other roadto - the road the exits leads topublic Road getExit(int direction)
direction - direction to check
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||