public class Locomotive extends Vehicle
Locomotiveclass represents the locomotives of the trains in the game. The class extends the class
Vehicle, thus it can move, remember it's position and pull objects. It is responsible for the movement of the train by pulling it's first
Coachand triggering a chain-reaction in all the following coaches. It is also responsible for triggering a similar chain-reaction of emptying and filling the
PassengerCoaches by trying to make their passengers get off at the
Stations next to the
Slots they are standing on, then trying to make the passengers waiting at the aforementioned
Stations get on.
|Constructor and Description|
|Modifier and Type||Method and Description|
Returns if the
arrive, depart, getCurrentPlace, getNextCoach, setCurrentPlace, setNextCoach, setNextCoach
public Locomotive(Slot currentPlace, Controller controller)
controller- the controller to notify if the locomotive crashes or gets empty.
public void step()
Locomotiveto the next position. It lets go of its current position and occupies the next position and pulls the object connected to it. The next position is calculated by the
Slotoccupied by this
Locomotiveby giving it this
Locomotive's current position. It also pulls the
Trailableobject it is pulling, and passes it the information that there are no passengers on this
Locomotivewhich should have nothing ahead pulling it.
public boolean checkCollision()
Slotit's on has any collisions currently, that is, if it has more than one occupants currently.
Slotoccupied by this has at least 2 occupants,
falseif it doesn't
public void accept(Vehicle.Visitor visitor)