com.TeamHEC.LocomotionCommotion.Train
Class Route

java.lang.Object
  extended by com.TeamHEC.LocomotionCommotion.Train.Route

public class Route
extends java.lang.Object

Author:
Matthew Taylor

Field Summary
 Train train
           
 
Constructor Summary
Route(java.util.ArrayList<Connection> path, int routeIndex, float connectionTravelled)
          Used to reload an existing route
Route(MapObj startingPos)
          Creates an arrayList of connections (a route) for tge train to eventually follow
 
Method Summary
 void abortRoute()
          Removes all connections from the route and resets the train position to the last station it past.
 void addConnection(Connection connection)
          Adds a new connection to the end of the route, if the player has enough fiel Usually one of the connections return from getAdjacentConnections()
 void cancelRoute()
          A repeated undo
 java.util.ArrayList<Connection> getAdjacentConnections()
          Can be used to see which adjacent connections are available to add to an existing route
 float getConnectionTravelled()
           
 float getLengthRemaining()
           
 java.util.ArrayList<Connection> getRoute()
           
 int getRouteIndex()
           
 Station getStation()
           
 float getTotalLength()
           
 com.badlogic.gdx.math.Vector2 getTrainPos()
          Returns Vector2 containing x and y position of the Train in the Route.
 void hideConnectionBlips(Connection connection)
           
 void hideRouteBlips()
          Removes route UI blips from the screen
 boolean inStation()
           
 boolean isComplete()
          Set to true when the route reaches an end in update method
 void notifyStationPassed()
          Notifies all listeners that a station has been passed by a train while completely it's route.
 void register(RouteListener newListener)
          Adds an object to the listener array
 boolean removeConnection()
          Removes the latest connection from the route.
 void setConnectionTravelled(float travelled)
          Can be used to change the position of the train within the route
 void setCurrentMapObj(MapObj current)
          The currentMapObj the train is positioned at
 void setRouteIndex(int index)
          Can be used to change the position of the train within the route
 void showConnectionBlips(Connection connection)
          Creates route UI dots for this connection
 void showRouteBlips()
          Makes all the white route blips between connections visible, the red dot indicates direction
 void unregister(RouteListener removeListener)
          Removes an object from the Listener array
 void update(float moveBy)
          Progressed a train in the route by certain amount - normally it's speed
 void updateRouteText()
          Updates the text displaying the route information:
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

train

public Train train
Constructor Detail

Route

public Route(MapObj startingPos)
Creates an arrayList of connections (a route) for tge train to eventually follow

Parameters:
startingPos - the starting position of the route

Route

public Route(java.util.ArrayList<Connection> path,
             int routeIndex,
             float connectionTravelled)
Used to reload an existing route

Parameters:
path - current route of the train
routeIndex - The index used to track progress through an array of connections
connectionTravelled - The distance travelled through that connection
Method Detail

getRoute

public java.util.ArrayList<Connection> getRoute()
Returns:
An Arraylist of connections within the route

getRouteIndex

public int getRouteIndex()
Returns:
The current position of the train within the connections ArrayList

isComplete

public boolean isComplete()
Set to true when the route reaches an end in update method

Returns:
if the route is complete

getConnectionTravelled

public float getConnectionTravelled()
Returns:
The amount a train has progress through the current connection in a route

setRouteIndex

public void setRouteIndex(int index)
Can be used to change the position of the train within the route

Parameters:
index - the index of the connection to move the train to

setConnectionTravelled

public void setConnectionTravelled(float travelled)
Can be used to change the position of the train within the route

Parameters:
travelled - The position of the train in the current connection

setCurrentMapObj

public void setCurrentMapObj(MapObj current)
The currentMapObj the train is positioned at


getAdjacentConnections

public java.util.ArrayList<Connection> getAdjacentConnections()
Can be used to see which adjacent connections are available to add to an existing route

Returns:
an ArrayList of adjacent connections to the latest connection in the route.

showRouteBlips

public void showRouteBlips()
Makes all the white route blips between connections visible, the red dot indicates direction


hideRouteBlips

public void hideRouteBlips()
Removes route UI blips from the screen


showConnectionBlips

public void showConnectionBlips(Connection connection)
Creates route UI dots for this connection

Parameters:
connection - the connection to add UI blips to

hideConnectionBlips

public void hideConnectionBlips(Connection connection)
Parameters:
connection - The connection to hide UI blips for

addConnection

public void addConnection(Connection connection)
Adds a new connection to the end of the route, if the player has enough fiel Usually one of the connections return from getAdjacentConnections()

Parameters:
connection - The connection to be added

removeConnection

public boolean removeConnection()
Removes the latest connection from the route. Used to undo latest addition.

Returns:
returns true if remove successful

abortRoute

public void abortRoute()
Removes all connections from the route and resets the train position to the last station it past. Can be used to reset a train when it collides with another or when a route is completely aborted.


cancelRoute

public void cancelRoute()
A repeated undo


updateRouteText

public void updateRouteText()
Updates the text displaying the route information:


getTrainPos

public com.badlogic.gdx.math.Vector2 getTrainPos()
Returns Vector2 containing x and y position of the Train in the Route. Calculated using the route index and connectionTravelled by scaling the direction vector within a connection

Returns:
a Vector containing the coordinates of the Train on the map

getTotalLength

public float getTotalLength()
Returns:
The length of the route from start to end

getLengthRemaining

public float getLengthRemaining()
Returns:
The length of the route remaining

inStation

public boolean inStation()
Returns:
if the train is currently in a station

getStation

public Station getStation()
Returns:
The station instance of the station the Train is in. Null if between stations

update

public void update(float moveBy)
Progressed a train in the route by certain amount - normally it's speed

Parameters:
moveBy - how much to progress the Train through the route by

register

public void register(RouteListener newListener)
Adds an object to the listener array


unregister

public void unregister(RouteListener removeListener)
Removes an object from the Listener array


notifyStationPassed

public void notifyStationPassed()
Notifies all listeners that a station has been passed by a train while completely it's route. Can be used to tax trains for passing rival stations