public class Truck extends java.lang.Object implements BoardElement, java.lang.Runnable
Modifier and Type | Class and Description |
---|---|
static class |
Truck.Status
The Two states that a Truck can be in at any time - either Waiting (staying
on its location and awaiting further travel instructions) or Traveling
(currently moving from node to node according to its travel instructions).
|
Modifier and Type | Field and Description |
---|---|
static int |
EFFICIENT_SPEED
Most efficient length/frame speed that a truck can travel, in terms of
total cost for traveling a given length.
|
Game |
game
The game to which this truck belongs.
|
static int |
MAX_SPEED
Maximum length/frame speed that a truck can travel.
|
static int |
MIN_SPEED
Minimum length/frame speed that a truck can travel.
|
static int |
WAIT_TIME
Milliseconds between wait updates - a truck calling
Manager.truckNotification(this, Notification.WAITING) .
|
COLOR_TOKEN, DESTINATION_TOKEN, LENGTH_TOKEN, LOCATION_TOKEN, NAME_TOKEN, X_TOKEN, Y_TOKEN
Modifier and Type | Method and Description |
---|---|
void |
addToTravel(Edge r)
Add road r to this Truck's travel plans, in a fashion that prevents
thread collision.
|
void |
clearTravel()
Clear the Truck's travel plans, in a fashion that prevents thread collision.
|
void |
dropoffLoad()
Drop off load at the current location.
|
Board |
getBoard()
Return the board to which this Truck belongs.
|
Circle |
getCircle()
Return the circle that represents this truck when it is drawn
|
java.awt.Color |
getColor()
Return the Color of this Truck.
|
Node |
getComingFrom()
Return the node this truck is coming from, the rear exit of the edge it
is currently on.
|
Node |
getGoingTo()
Return the Truck's eventual destination; the Node this Truck will be at
when the current travel queue is empty.
|
Parcel |
getLoad()
Return the parcel this Truck is carrying.
|
Node |
getLocation()
Return the Truck's current location.
|
Manager |
getManager()
Return the manager that is managing this truck.
|
java.lang.String |
getMappedName()
Return the name of this truck to display on the GUI.
|
int |
getRelativeX()
Return the location of this' name relative to its position on the GUI.
|
int |
getRelativeY()
Return the location of this' name relative to its position on the GUI.
|
int |
getSpeed()
Return the speed this truck will/is traveling.
|
Truck.Status |
getStatus()
Return the current status of this Truck, either TRAVELING or WAITING.
|
Edge |
getTravelingAlong()
Return the edge this Truck is traveling along.
|
Node |
getTravelingTo()
Return the Truck's current destination.
|
java.lang.String |
getTruckName()
Return the name of this Truck.
|
java.lang.Object |
getUserData()
Return the userData stored in this Node.
|
boolean |
isAlive()
Return true iff this Truck is alive (executing its run loop).
|
boolean |
isColorSignificant()
Return true - the color of Trucks is significant
|
boolean |
isTruckHere(Truck t)
Return true for this and return false for other trucks,
because a truck is always "at" itself.
|
boolean |
isWaitingForManager()
Return true iff this truck is waiting for manager input.
|
void |
pickupLoad(Parcel p)
Pick up parcel p at the current location.
|
void |
run()
The Truck's main running routine.
|
void |
setSpeed(int newSpeed)
Set this trucks speed.
|
void |
setTravelPath(java.util.List<Node> path)
Clear the travel queue, then
Set the travel queue to travel the given path.
|
void |
setTravelQueue(java.util.List<Edge> path)
Clear the Travel queue, then
Set the travel queue to travel the given list of edges, in order.
|
void |
setTruckName(java.lang.String newName)
Set the name of this Truck to newName and, if it is not yet assigned
to this thread, set it to this thread.
|
void |
setUserData(java.lang.Object uData)
Set the value of userData to uData.
|
java.lang.String |
toJSONString()
Return a JSON String of this truck.
|
java.lang.String |
toString()
Return a string representation of this Truck --its name.
|
int |
trucksHere()
Return 1 -- there is always one truck at itself
|
void |
updateGUILocation(int x,
int y)
Update the circle graphic that represents this truck on the GUI.
|
public static final int WAIT_TIME
public static final int MAX_SPEED
public static final int EFFICIENT_SPEED
public static final int MIN_SPEED
public final Game game
public void run()
run
in interface java.lang.Runnable
public Manager getManager()
public Board getBoard()
getBoard
in interface BoardElement
public java.lang.String getTruckName()
public void setTruckName(java.lang.String newName)
public boolean isAlive()
public Node getLocation()
public Node getTravelingTo()
public Edge getTravelingAlong()
public Node getComingFrom()
public Node getGoingTo()
public Truck.Status getStatus()
public boolean isWaitingForManager()
public Parcel getLoad()
public java.awt.Color getColor()
public boolean isColorSignificant()
isColorSignificant
in interface Colorable
public int getSpeed()
public void setSpeed(int newSpeed)
public java.lang.Object getUserData()
getUserData
in interface UserData
public void setUserData(java.lang.Object uData)
setUserData
in interface UserData
public void pickupLoad(Parcel p) throws java.lang.RuntimeException
java.lang.RuntimeException
- - if load is not null (can't pick up) or
if this Truck is currently traveling.public void dropoffLoad() throws java.lang.RuntimeException
java.lang.RuntimeException
public Circle getCircle()
public void addToTravel(Edge r)
public void setTravelQueue(java.util.List<Edge> path)
public void setTravelPath(java.util.List<Node> path) throws java.lang.RuntimeException
java.lang.RuntimeException
- if the truck isn't currently at the first node in the path.public void clearTravel()
public void updateGUILocation(int x, int y)
updateGUILocation
in interface BoardElement
x
- - the new X location of this Truck in the GUIy
- - the new Y location of this Truck in the GUIpublic java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String getMappedName()
getMappedName
in interface BoardElement
public int getRelativeX()
getRelativeX
in interface BoardElement
public int getRelativeY()
getRelativeY
in interface BoardElement
public boolean isTruckHere(Truck t)
isTruckHere
in interface BoardElement
public int trucksHere()
trucksHere
in interface BoardElement
public java.lang.String toJSONString()
toJSONString
in interface org.json.JSONString