public class Locomotive extends Vehicle
Locomotive
class 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 Coach
and triggering a chain-reaction in all the following coaches. It is also responsible for
triggering a similar chain-reaction of emptying and filling the PassengerCoach
es
by trying to make their passengers get off at the Station
s next to the Slot
s
they are standing on, then trying to make the passengers waiting at the aforementioned
Station
s get on.Vehicle.Visitor
Constructor and Description |
---|
Locomotive(Slot currentPlace,
Controller controller)
Creates a
Locomotive occupying the Slot given by currentPlace
pulling a NotifierCoach . |
Modifier and Type | Method and Description |
---|---|
void |
accept(Vehicle.Visitor visitor) |
boolean |
checkCollision()
Returns if the
Slot it's on has any collisions currently, that is,
if it has more than one occupants currently. |
void |
step()
Moves this
Locomotive to the next position. |
arrive, depart, getCurrentPlace, getNextCoach, setCurrentPlace, setNextCoach, setNextCoach
public Locomotive(Slot currentPlace, Controller controller)
Locomotive
occupying the Slot
given by currentPlace
pulling a NotifierCoach
.currentPlace
- the Slot
given by currentPlace
this Locomotive
controller
- the controller to notify if the locomotive crashes or gets empty.public void step()
Locomotive
to 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 Slot
occupied by
this Locomotive
by giving it this Locomotive
's current position.
It also pulls the Trailable
object it is pulling, and passes it the information
that there are no passengers on this Locomotive
which should have nothing ahead pulling it.public boolean checkCollision()
Slot
it's on has any collisions currently, that is,
if it has more than one occupants currently.true
if the Slot
occupied by this has at least 2 occupants,
false
if it doesn'tpublic void accept(Vehicle.Visitor visitor)