27
27
* Kolatat Thangkasemvathana [780631]
28
28
* Khai Mei Chin [755332]
29
29
*
30
+ * Active Station Class
30
31
*/
31
32
32
33
public class ActiveStation extends Station {
34
+
33
35
// Logger
34
36
private static Logger logger = LogManager .getLogger ();
35
37
36
38
PassengerGenerator g ;
37
39
ArrayList <Passenger > waiting ;
38
40
float maxVolume ;
39
41
42
+ /**
43
+ * Constructor for ActiveStation.
44
+ * @param x x-coordinate of the station
45
+ * @param y y-coordinate of the station
46
+ * @param router router to be use
47
+ * @param name name of the station
48
+ * @param maxPax station maximum passenger capacity
49
+ */
40
50
public ActiveStation (float x , float y , PassengerRouter router , String name , float maxPax ) {
41
51
super (x , y , router , name );
42
52
this .waiting = new ArrayList <Passenger >();
43
53
this .g = new PassengerGenerator (this , this .lines , maxPax );
44
54
this .maxVolume = maxPax ;
45
55
}
46
56
57
+
58
+ /**
59
+ * Checker to see if a train is compatible with this type of station
60
+ * @param t Train to check for compatibility
61
+ * @return True if the Train is not an instance of CargoTrain
62
+ * @throws Exception
63
+ */
47
64
@ Override
48
- // Only PassengerTrains can stop at ActiveStations
49
65
public boolean compatible (Train t ) throws Exception {
66
+ // Only PassengerTrains can stop at ActiveStations
50
67
return !(t instanceof CargoTrain );
51
68
}
52
69
70
+
71
+ /**
72
+ * Entry of a train into this station
73
+ * @param t Train to enter this station
74
+ * @throws Exception
75
+ */
53
76
@ Override
54
77
// Generate passengers when a train has entered the station
55
78
public void enter (Train t ) throws Exception {
@@ -81,15 +104,17 @@ public void enter(Train t) throws Exception {
81
104
82
105
/**
83
106
* Embarking passengers onto train
84
- * @param t Train for passengers to get on
107
+ * @param t Train for passengers to get on
85
108
*/
86
109
public void addWaitingPassengers (Train t ){
87
110
Iterator <Passenger > pIter = this .waiting .iterator ();
88
111
while (pIter .hasNext ()){
89
112
Passenger p = pIter .next ();
90
113
try {
91
- logger .info ("Passenger " + p .getID () + " carrying " + p .getCargo ().getWeight ()
92
- + " kg cargo embarking at " + this .name + " heading to " +p .getDestination ().name );
114
+ logger .info ("Passenger " + p .getID ()
115
+ + " carrying " + p .getCargo ().getWeight ()
116
+ + " kg cargo embarking at " + this .name
117
+ + " heading to " + p .getDestination ().name );
93
118
t .embark (p );
94
119
pIter .remove ();
95
120
} catch (Exception e ){
@@ -100,7 +125,12 @@ public void addWaitingPassengers(Train t){
100
125
}
101
126
102
127
128
+ /**
129
+ * Renders the station
130
+ * @param renderer ShapeRenderer
131
+ */
103
132
@ Override
133
+ // Renderer for the ActiveStation
104
134
public void render (ShapeRenderer renderer ){
105
135
// Show a station as a rings of lines
106
136
float radius = RADIUS ;
@@ -112,22 +142,25 @@ public void render(ShapeRenderer renderer){
112
142
if (this .waiting .size () > 0 ){
113
143
c = Color .RED ;
114
144
}
115
-
116
145
renderer .setColor (c );
117
146
renderer .circle (this .position .x , this .position .y , radius , NUM_CIRCLE_STATMENTS );
118
147
}
119
148
149
+
150
+ /**
151
+ * Renders the number of passengers waiting at the station
152
+ * @param b SpriteBatch
153
+ * @param font font used to render the text
154
+ */
120
155
@ Override
121
- public void renderWaiting (SpriteBatch b , BitmapFont header , boolean waiting ){
122
- if (waiting ){
123
- b .begin ();
124
- header .getData ().setScale (1f );
125
- header .draw (
126
- b ,
127
- Integer .toString (this .waiting .size ()),
128
- this .position .x -10 ,
129
- this .position .y -10 );
130
- b .end ();
131
- }
156
+ public void renderWaiting (SpriteBatch b , BitmapFont font ){
157
+ b .begin ();
158
+ font .getData ().setScale (1f );
159
+ font .draw (
160
+ b ,
161
+ Integer .toString (this .waiting .size ()),
162
+ this .position .x -10 ,
163
+ this .position .y -10 );
164
+ b .end ();
132
165
}
133
166
}
0 commit comments