Skip to content

Commit

Permalink
Merge pull request #18 from natebwangsut/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
natebwangsut authored Apr 27, 2017
2 parents 4b5d302 + 784fdd6 commit 6836d7d
Show file tree
Hide file tree
Showing 25 changed files with 376 additions and 102 deletions.
9 changes: 7 additions & 2 deletions core/src/com/unimelb/swen30006/metromadness/MetroMadness.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,12 @@ private void handleInput() {
float effectiveViewportWidth = camera.viewportWidth * camera.zoom;
float effectiveViewportHeight = camera.viewportHeight * camera.zoom;

camera.position.x = MathUtils.clamp(camera.position.x, effectiveViewportWidth / 2f, WORLD_WIDTH - effectiveViewportWidth / 2f);
camera.position.y = MathUtils.clamp(camera.position.y, effectiveViewportHeight / 2f, WORLD_HEIGHT - effectiveViewportHeight / 2f);
camera.position.x = MathUtils.clamp(
camera.position.x,
effectiveViewportWidth / 2f,
WORLD_WIDTH - effectiveViewportWidth / 2f);
camera.position.y = MathUtils.clamp(camera.position.y,
effectiveViewportHeight / 2f,
WORLD_HEIGHT - effectiveViewportHeight / 2f);
}
}
21 changes: 17 additions & 4 deletions core/src/com/unimelb/swen30006/metromadness/Simulation.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ public void update(){
}
}

/**
* Render the Simulation.
* @param renderer Renderer to be use on each seperate class
* @param b Batch to draw the font on
* @param font Font that use to render on the simulation
* @param station Boolean value to show the station or not
* @param passenger Boolean value to show the passengers or not
* @param waiting Boolean value to show the waiting passengers or not
* @param train Boolean value to show the trains or not
*/
public void render(
ShapeRenderer renderer,
SpriteBatch b,
Expand All @@ -64,20 +74,23 @@ public void render(
boolean waiting,
boolean train) {

// Renders all the tracks
for(Line l: this.lines){
l.render(renderer);
}

// Renders all the trains
for(Train t: this.trains){
t.render(renderer);
t.renderName(b, font, train);
t.renderPassengers(b, font, passenger);
if (train) {t.renderName(b, font);}
if (passenger) {t.renderPassengers(b, font);}
}

// Renders all the stations
for(Station s: this.stations){
s.render(renderer);
s.renderName(b, font, station);
s.renderWaiting(b, font, waiting);
if (station) {s.renderName(b, font);}
if (waiting) {s.renderWaiting(b, font);}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Kolatat Thangkasemvathana [780631]
* Khai Mei Chin [755332]
*
* Cannot find a particular platform
*/

public class StationNotFoundException extends Exception{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Kolatat Thangkasemvathana [780631]
* Khai Mei Chin [755332]
*
* Cannot find a particular track
*/

public class TrackNotFoundException extends Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Kolatat Thangkasemvathana [780631]
* Khai Mei Chin [755332]
*
* Passenger tries to enter the train when the cargo space is not enough to facilitate
*/

public class TrainCargoFullException extends Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.unimelb.swen30006.metromadness.exceptions;

/**
* [SWEN30006] Software Modelling and Design
* Semester 1, 2017
* Project Part B - Metro Madness
*
* Group 107:
* Nate Wangsutthitham [755399]
* Kolatat Thangkasemvathana [780631]
* Khai Mei Chin [755332]
*
* Exception if the Passengers with Cargo tries to enter invalid Train.
*/

public class TrainNoCargoException extends Exception {
public TrainNoCargoException() {
super("Error: Passengers with Cargo tries to enter Train that cannot contain Cargo.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Kolatat Thangkasemvathana [780631]
* Khai Mei Chin [755332]
*
* Cannot find a particular train
*/

public class TrainNotFoundException extends Exception{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Kolatat Thangkasemvathana [780631]
* Khai Mei Chin [755332]
*
* Passenger tries to enter the train when the seats are not enough to facilitate
*/

public class TrainPassengerFullException extends Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* Kolatat Thangkasemvathana [780631]
* Khai Mei Chin [755332]
*
* Passenger Class
*/

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

// Do not generate cargo if not from CargoStation
// Do not generate cargo if not from CargoStation class
if (start instanceof CargoStation) {
this.cargo = generateCargo(random);
} else {
this.cargo = new Cargo(0);
}
}


public int getID(){
return this.id;
}
Expand All @@ -60,8 +60,7 @@ public void update(float time){
}
}


// Encapsulated Cargo class and its methods
// Encapsulated Cargo class and its methods into Passenger
public class Cargo{
private int weight;

Expand All @@ -85,6 +84,4 @@ public Cargo generateCargo(Random random){
public Cargo getCargo(){
return cargo;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* Kolatat Thangkasemvathana [780631]
* Khai Mei Chin [755332]
*
* Generator class which generates Passenger
*/

public class PassengerGenerator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
* Kolatat Thangkasemvathana [780631]
* Khai Mei Chin [755332]
*
* Router Interface for Passenger
*/

public interface PassengerRouter {

public boolean shouldLeave(Station current, Passenger p);

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* Kolatat Thangkasemvathana [780631]
* Khai Mei Chin [755332]
*
* Router class for Passenger
*/

public class SimpleRouter implements PassengerRouter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,52 @@
* Kolatat Thangkasemvathana [780631]
* Khai Mei Chin [755332]
*
* Active Station Class
*/

public class ActiveStation extends Station {

// Logger
private static Logger logger = LogManager.getLogger();

PassengerGenerator g;
ArrayList<Passenger> waiting;
float maxVolume;

/**
* Constructor for ActiveStation.
* @param x x-coordinate of the station
* @param y y-coordinate of the station
* @param router router to be use
* @param name name of the station
* @param maxPax station maximum passenger capacity
*/
public ActiveStation(float x, float y, PassengerRouter router, String name, float maxPax) {
super(x, y, router, name);
this.waiting = new ArrayList<Passenger>();
this.g = new PassengerGenerator(this, this.lines, maxPax);
this.maxVolume = maxPax;
}


/**
* Checker to see if a train is compatible with this type of station
* @param t Train to check for compatibility
* @return True if the Train is not an instance of CargoTrain
* @throws Exception
*/
@Override
// Only PassengerTrains can stop at ActiveStations
public boolean compatible(Train t) throws Exception {
// Only PassengerTrains can stop at ActiveStations
return !(t instanceof CargoTrain);
}


/**
* Entry of a train into this station
* @param t Train to enter this station
* @throws Exception
*/
@Override
// Generate passengers when a train has entered the station
public void enter(Train t) throws Exception {
Expand Down Expand Up @@ -81,15 +104,17 @@ public void enter(Train t) throws Exception {

/**
* Embarking passengers onto train
* @param t Train for passengers to get on
* @param t Train for passengers to get on
*/
public void addWaitingPassengers(Train t){
Iterator<Passenger> pIter = this.waiting.iterator();
while(pIter.hasNext()){
Passenger p = pIter.next();
try {
logger.info("Passenger " + p.getID() + " carrying " + p.getCargo().getWeight()
+ " kg cargo embarking at " + this.name + " heading to "+p.getDestination().name);
logger.info("Passenger " + p.getID()
+ " carrying " + p.getCargo().getWeight()
+ " kg cargo embarking at " + this.name
+ " heading to " + p.getDestination().name);
t.embark(p);
pIter.remove();
} catch (Exception e){
Expand All @@ -100,7 +125,12 @@ public void addWaitingPassengers(Train t){
}


/**
* Renders the station
* @param renderer ShapeRenderer
*/
@Override
// Renderer for the ActiveStation
public void render(ShapeRenderer renderer){
// Show a station as a rings of lines
float radius = RADIUS;
Expand All @@ -112,22 +142,25 @@ public void render(ShapeRenderer renderer){
if(this.waiting.size() > 0){
c = Color.RED;
}

renderer.setColor(c);
renderer.circle(this.position.x, this.position.y, radius, NUM_CIRCLE_STATMENTS);
}


/**
* Renders the number of passengers waiting at the station
* @param b SpriteBatch
* @param font font used to render the text
*/
@Override
public void renderWaiting(SpriteBatch b, BitmapFont header, boolean waiting){
if(waiting){
b.begin();
header.getData().setScale(1f);
header.draw(
b,
Integer.toString(this.waiting.size()),
this.position.x-10,
this.position.y-10);
b.end();
}
public void renderWaiting(SpriteBatch b, BitmapFont font){
b.begin();
font.getData().setScale(1f);
font.draw(
b,
Integer.toString(this.waiting.size()),
this.position.x-10,
this.position.y-10);
b.end();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,37 @@ public class CargoStation extends ActiveStation {
// Logger
private static Logger logger = LogManager.getLogger();


/**
* Constructor for CargoStation.
* @param x x-coordinate of the station
* @param y y-coordinate of the station
* @param router router to be use
* @param name name of the station
* @param maxPax station maximum passenger capacity
*/
public CargoStation(float x, float y, PassengerRouter router, String name, float maxPax) {
// Use ActiveStation constructor to create CargoStation
super(x, y, router, name, maxPax);
}


/**
* Checker to see if a train is compatible with this type of station
* @param t Train to check for compatibility
* @return Always true since any train can enter CargoStation
* @throws Exception
*/
@Override
// Any type of train can enter a CargoStation
public boolean compatible(Train t) throws Exception {
// Any type of train can enter a CargoStation
return true;
}


/**
* Renders the station
* @param renderer ShapeRenderer
*/
@Override
// A cargo station is rendered as an orange circle instead of white
public void render(ShapeRenderer renderer){
Expand All @@ -64,6 +83,12 @@ public void render(ShapeRenderer renderer){
renderer.circle(this.position.x, this.position.y, radius, NUM_CIRCLE_STATMENTS);
}


/**
* Entry of a train into this station
* @param t Train to enter this station
* @throws Exception
*/
@Override
// Generate passengers when a train has entered the station
public void enter(Train t) throws Exception {
Expand All @@ -86,7 +111,10 @@ public void enter(Train t) throws Exception {
if(p==null){
return;
}
logger.info("Passenger "+p.getID()+" carrying "+p.getCargo().getWeight() +" kg embarking at "+this.name+" heading to "+p.getDestination().name);
logger.info("Passenger " + p.getID()
+ " carrying " + p.getCargo().getWeight()
+ " kg embarking at " + this.name
+ " heading to " + p.getDestination().name);
t.embark(p);
} catch(Exception e){
this.waiting.add(p);
Expand Down
Loading

0 comments on commit 6836d7d

Please sign in to comment.