-
Notifications
You must be signed in to change notification settings - Fork 0
/
TrackSwitchTopRight.java
43 lines (38 loc) · 1.36 KB
/
TrackSwitchTopRight.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot und MouseInfo)
/**
* Repräsentiert eine TOP-RIGHT-Switch, d.h. Weiche, die von oben kommende
* Züge im ungestellten Zustand vertikal leitet, im gestellten Zustand nach rechts.
*
* @author Leonard Bienbeck
* @version 1.0.0
*/
public class TrackSwitchTopRight extends Switch
{
/**
* Erzeugt eine TOP-RIGHT-Switch
*/
public TrackSwitchTopRight() {
super(TrackType.SWITCH_TOPRIGHT, "switch_top_right_");
super.setSwitched(false);
}
public Track determineNextTrack(Direction movingDirection) {
Direction newDirection = null;
switch(movingDirection) {
case BOTTOM:
newDirection = this.isSwitched() ? Direction.RIGHT : Direction.BOTTOM;
break;
default:
newDirection = Direction.TOP;
break;
}
return this.getNeighbourAt(newDirection);
}
public Direction getReversedDirection(Direction movingDirection) {
switch(movingDirection) {
case TOP: return this.isSwitched() ? Direction.LEFT : Direction.BOTTOM;
case BOTTOM: return Direction.TOP;
case LEFT: return this.isSwitched() ? Direction.BOTTOM : Direction.RIGHT;
default: return Direction.TOP;
}
}
}