public class Coach extends Vehicle implements Trailable
Coach
class implements the coal wagons of the trains in the game.
A Coach
is pulled by the Vehicle
it's connected to, that is, the
Vehicle
's nextCoach attribute is this.
This behaviour is provided by the Trailable
interface being implemented by Coach
,
and calling its step
method.Vehicle.Visitor
Constructor and Description |
---|
Coach(Slot currentPlace)
Creates a
Coach occupying the position given by currentPlace
pulling the object given by nextCoach . |
Modifier and Type | Method and Description |
---|---|
void |
accept(Vehicle.Visitor visitor) |
void |
step(Slot nextSlot,
boolean hasPassengersAhead)
Moves the
Coach to the position given by nextSlot . |
arrive, depart, getCurrentPlace, getNextCoach, setCurrentPlace, setNextCoach, setNextCoach
public Coach(Slot currentPlace)
Coach
occupying the position given by currentPlace
pulling the object given by nextCoach
.currentPlace
- a Slot
occupied by the Coach
public void step(Slot nextSlot, boolean hasPassengersAhead)
Coach
to the position given by nextSlot
. It lets go of its
current position and occupies the newly given position and pulls
the object connected to it. In addition information about the presence of
passengers in any Vehicle
s ahead is passed in the form of the
parameter hasPassengersAhead
.
Between the position change and the pulling it also makes this Coach
arrive at
and depart from its currentPlace
.public void accept(Vehicle.Visitor visitor)