Skip to content

Commit 6836d7d

Browse files
authored
Merge pull request #18 from natebwangsut/develop
Develop
2 parents 4b5d302 + 784fdd6 commit 6836d7d

25 files changed

+376
-102
lines changed

core/src/com/unimelb/swen30006/metromadness/MetroMadness.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,12 @@ private void handleInput() {
189189
float effectiveViewportWidth = camera.viewportWidth * camera.zoom;
190190
float effectiveViewportHeight = camera.viewportHeight * camera.zoom;
191191

192-
camera.position.x = MathUtils.clamp(camera.position.x, effectiveViewportWidth / 2f, WORLD_WIDTH - effectiveViewportWidth / 2f);
193-
camera.position.y = MathUtils.clamp(camera.position.y, effectiveViewportHeight / 2f, WORLD_HEIGHT - effectiveViewportHeight / 2f);
192+
camera.position.x = MathUtils.clamp(
193+
camera.position.x,
194+
effectiveViewportWidth / 2f,
195+
WORLD_WIDTH - effectiveViewportWidth / 2f);
196+
camera.position.y = MathUtils.clamp(camera.position.y,
197+
effectiveViewportHeight / 2f,
198+
WORLD_HEIGHT - effectiveViewportHeight / 2f);
194199
}
195200
}

core/src/com/unimelb/swen30006/metromadness/Simulation.java

+17-4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ public void update(){
5555
}
5656
}
5757

58+
/**
59+
* Render the Simulation.
60+
* @param renderer Renderer to be use on each seperate class
61+
* @param b Batch to draw the font on
62+
* @param font Font that use to render on the simulation
63+
* @param station Boolean value to show the station or not
64+
* @param passenger Boolean value to show the passengers or not
65+
* @param waiting Boolean value to show the waiting passengers or not
66+
* @param train Boolean value to show the trains or not
67+
*/
5868
public void render(
5969
ShapeRenderer renderer,
6070
SpriteBatch b,
@@ -64,20 +74,23 @@ public void render(
6474
boolean waiting,
6575
boolean train) {
6676

77+
// Renders all the tracks
6778
for(Line l: this.lines){
6879
l.render(renderer);
6980
}
7081

82+
// Renders all the trains
7183
for(Train t: this.trains){
7284
t.render(renderer);
73-
t.renderName(b, font, train);
74-
t.renderPassengers(b, font, passenger);
85+
if (train) {t.renderName(b, font);}
86+
if (passenger) {t.renderPassengers(b, font);}
7587
}
7688

89+
// Renders all the stations
7790
for(Station s: this.stations){
7891
s.render(renderer);
79-
s.renderName(b, font, station);
80-
s.renderWaiting(b, font, waiting);
92+
if (station) {s.renderName(b, font);}
93+
if (waiting) {s.renderWaiting(b, font);}
8194
}
8295
}
8396
}

core/src/com/unimelb/swen30006/metromadness/exceptions/StationNotFoundException.java

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* Kolatat Thangkasemvathana [780631]
1111
* Khai Mei Chin [755332]
1212
*
13+
* Cannot find a particular platform
1314
*/
1415

1516
public class StationNotFoundException extends Exception{

core/src/com/unimelb/swen30006/metromadness/exceptions/TrackNotFoundException.java

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* Kolatat Thangkasemvathana [780631]
1111
* Khai Mei Chin [755332]
1212
*
13+
* Cannot find a particular track
1314
*/
1415

1516
public class TrackNotFoundException extends Exception {

core/src/com/unimelb/swen30006/metromadness/exceptions/TrainCargoFullException.java

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* Kolatat Thangkasemvathana [780631]
1111
* Khai Mei Chin [755332]
1212
*
13+
* Passenger tries to enter the train when the cargo space is not enough to facilitate
1314
*/
1415

1516
public class TrainCargoFullException extends Exception {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.unimelb.swen30006.metromadness.exceptions;
2+
3+
/**
4+
* [SWEN30006] Software Modelling and Design
5+
* Semester 1, 2017
6+
* Project Part B - Metro Madness
7+
*
8+
* Group 107:
9+
* Nate Wangsutthitham [755399]
10+
* Kolatat Thangkasemvathana [780631]
11+
* Khai Mei Chin [755332]
12+
*
13+
* Exception if the Passengers with Cargo tries to enter invalid Train.
14+
*/
15+
16+
public class TrainNoCargoException extends Exception {
17+
public TrainNoCargoException() {
18+
super("Error: Passengers with Cargo tries to enter Train that cannot contain Cargo.");
19+
}
20+
}

core/src/com/unimelb/swen30006/metromadness/exceptions/TrainNotFoundException.java

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* Kolatat Thangkasemvathana [780631]
1111
* Khai Mei Chin [755332]
1212
*
13+
* Cannot find a particular train
1314
*/
1415

1516
public class TrainNotFoundException extends Exception{

core/src/com/unimelb/swen30006/metromadness/exceptions/TrainPassengerFullException.java

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* Kolatat Thangkasemvathana [780631]
1111
* Khai Mei Chin [755332]
1212
*
13+
* Passenger tries to enter the train when the seats are not enough to facilitate
1314
*/
1415

1516
public class TrainPassengerFullException extends Exception {

core/src/com/unimelb/swen30006/metromadness/passengers/Passenger.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* Kolatat Thangkasemvathana [780631]
1616
* Khai Mei Chin [755332]
1717
*
18+
* Passenger Class
1819
*/
1920

2021
public class Passenger {
@@ -33,15 +34,14 @@ public Passenger(int id, Random random, Station start, Station end){
3334
this.reachedDestination = false;
3435
this.travelTime = 0;
3536

36-
// Do not generate cargo if not from CargoStation
37+
// Do not generate cargo if not from CargoStation class
3738
if (start instanceof CargoStation) {
3839
this.cargo = generateCargo(random);
3940
} else {
4041
this.cargo = new Cargo(0);
4142
}
4243
}
4344

44-
4545
public int getID(){
4646
return this.id;
4747
}
@@ -60,8 +60,7 @@ public void update(float time){
6060
}
6161
}
6262

63-
64-
// Encapsulated Cargo class and its methods
63+
// Encapsulated Cargo class and its methods into Passenger
6564
public class Cargo{
6665
private int weight;
6766

@@ -85,6 +84,4 @@ public Cargo generateCargo(Random random){
8584
public Cargo getCargo(){
8685
return cargo;
8786
}
88-
89-
9087
}

core/src/com/unimelb/swen30006/metromadness/passengers/PassengerGenerator.java

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* Kolatat Thangkasemvathana [780631]
1818
* Khai Mei Chin [755332]
1919
*
20+
* Generator class which generates Passenger
2021
*/
2122

2223
public class PassengerGenerator {

core/src/com/unimelb/swen30006/metromadness/routers/PassengerRouter.java

+3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313
* Kolatat Thangkasemvathana [780631]
1414
* Khai Mei Chin [755332]
1515
*
16+
* Router Interface for Passenger
1617
*/
1718

1819
public interface PassengerRouter {
20+
1921
public boolean shouldLeave(Station current, Passenger p);
22+
2023
}

core/src/com/unimelb/swen30006/metromadness/routers/SimpleRouter.java

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* Kolatat Thangkasemvathana [780631]
1414
* Khai Mei Chin [755332]
1515
*
16+
* Router class for Passenger
1617
*/
1718

1819
public class SimpleRouter implements PassengerRouter {

core/src/com/unimelb/swen30006/metromadness/stations/ActiveStation.java

+49-16
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,52 @@
2727
* Kolatat Thangkasemvathana [780631]
2828
* Khai Mei Chin [755332]
2929
*
30+
* Active Station Class
3031
*/
3132

3233
public class ActiveStation extends Station {
34+
3335
// Logger
3436
private static Logger logger = LogManager.getLogger();
3537

3638
PassengerGenerator g;
3739
ArrayList<Passenger> waiting;
3840
float maxVolume;
3941

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+
*/
4050
public ActiveStation(float x, float y, PassengerRouter router, String name, float maxPax) {
4151
super(x, y, router, name);
4252
this.waiting = new ArrayList<Passenger>();
4353
this.g = new PassengerGenerator(this, this.lines, maxPax);
4454
this.maxVolume = maxPax;
4555
}
4656

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+
*/
4764
@Override
48-
// Only PassengerTrains can stop at ActiveStations
4965
public boolean compatible(Train t) throws Exception {
66+
// Only PassengerTrains can stop at ActiveStations
5067
return !(t instanceof CargoTrain);
5168
}
5269

70+
71+
/**
72+
* Entry of a train into this station
73+
* @param t Train to enter this station
74+
* @throws Exception
75+
*/
5376
@Override
5477
// Generate passengers when a train has entered the station
5578
public void enter(Train t) throws Exception {
@@ -81,15 +104,17 @@ public void enter(Train t) throws Exception {
81104

82105
/**
83106
* Embarking passengers onto train
84-
* @param t Train for passengers to get on
107+
* @param t Train for passengers to get on
85108
*/
86109
public void addWaitingPassengers(Train t){
87110
Iterator<Passenger> pIter = this.waiting.iterator();
88111
while(pIter.hasNext()){
89112
Passenger p = pIter.next();
90113
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);
93118
t.embark(p);
94119
pIter.remove();
95120
} catch (Exception e){
@@ -100,7 +125,12 @@ public void addWaitingPassengers(Train t){
100125
}
101126

102127

128+
/**
129+
* Renders the station
130+
* @param renderer ShapeRenderer
131+
*/
103132
@Override
133+
// Renderer for the ActiveStation
104134
public void render(ShapeRenderer renderer){
105135
// Show a station as a rings of lines
106136
float radius = RADIUS;
@@ -112,22 +142,25 @@ public void render(ShapeRenderer renderer){
112142
if(this.waiting.size() > 0){
113143
c = Color.RED;
114144
}
115-
116145
renderer.setColor(c);
117146
renderer.circle(this.position.x, this.position.y, radius, NUM_CIRCLE_STATMENTS);
118147
}
119148

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+
*/
120155
@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();
132165
}
133166
}

core/src/com/unimelb/swen30006/metromadness/stations/CargoStation.java

+31-3
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,37 @@ public class CargoStation extends ActiveStation {
3333
// Logger
3434
private static Logger logger = LogManager.getLogger();
3535

36-
36+
/**
37+
* Constructor for CargoStation.
38+
* @param x x-coordinate of the station
39+
* @param y y-coordinate of the station
40+
* @param router router to be use
41+
* @param name name of the station
42+
* @param maxPax station maximum passenger capacity
43+
*/
3744
public CargoStation(float x, float y, PassengerRouter router, String name, float maxPax) {
45+
// Use ActiveStation constructor to create CargoStation
3846
super(x, y, router, name, maxPax);
3947
}
4048

49+
50+
/**
51+
* Checker to see if a train is compatible with this type of station
52+
* @param t Train to check for compatibility
53+
* @return Always true since any train can enter CargoStation
54+
* @throws Exception
55+
*/
4156
@Override
42-
// Any type of train can enter a CargoStation
4357
public boolean compatible(Train t) throws Exception {
58+
// Any type of train can enter a CargoStation
4459
return true;
4560
}
4661

4762

63+
/**
64+
* Renders the station
65+
* @param renderer ShapeRenderer
66+
*/
4867
@Override
4968
// A cargo station is rendered as an orange circle instead of white
5069
public void render(ShapeRenderer renderer){
@@ -64,6 +83,12 @@ public void render(ShapeRenderer renderer){
6483
renderer.circle(this.position.x, this.position.y, radius, NUM_CIRCLE_STATMENTS);
6584
}
6685

86+
87+
/**
88+
* Entry of a train into this station
89+
* @param t Train to enter this station
90+
* @throws Exception
91+
*/
6792
@Override
6893
// Generate passengers when a train has entered the station
6994
public void enter(Train t) throws Exception {
@@ -86,7 +111,10 @@ public void enter(Train t) throws Exception {
86111
if(p==null){
87112
return;
88113
}
89-
logger.info("Passenger "+p.getID()+" carrying "+p.getCargo().getWeight() +" kg embarking at "+this.name+" heading to "+p.getDestination().name);
114+
logger.info("Passenger " + p.getID()
115+
+ " carrying " + p.getCargo().getWeight()
116+
+ " kg embarking at " + this.name
117+
+ " heading to " + p.getDestination().name);
90118
t.embark(p);
91119
} catch(Exception e){
92120
this.waiting.add(p);

0 commit comments

Comments
 (0)