mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Reformatted doctring and import statements
This commit is contained in:
@@ -1,87 +1,86 @@
|
||||
package seng302;
|
||||
|
||||
import java.util.*;
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public class App
|
||||
{
|
||||
/**
|
||||
* Builds a race object for the AC35 course
|
||||
*/
|
||||
public static Race createRace() throws Exception{
|
||||
Race race = new Race();
|
||||
public class App {
|
||||
/**
|
||||
* Builds a race object for the AC35 course
|
||||
*/
|
||||
public static Race createRace() throws Exception {
|
||||
Race race = new Race();
|
||||
|
||||
// Read team names from file
|
||||
FileParser fp = new FileParser("doc/examples/config.json");
|
||||
ArrayList<String> boatNames = new ArrayList<>();
|
||||
ArrayList<Map<String, Object>> teams = fp.getTeams();
|
||||
// Read team names from file
|
||||
FileParser fp = new FileParser("doc/examples/config.json");
|
||||
ArrayList<String> boatNames = new ArrayList<>();
|
||||
ArrayList<Map<String, Object>> teams = fp.getTeams();
|
||||
|
||||
//get race size
|
||||
int numberOfBoats = (int) fp.getRaceSize();
|
||||
//get race size
|
||||
int numberOfBoats = (int) fp.getRaceSize();
|
||||
|
||||
//get time scale
|
||||
double timeScale = fp.getTimeScale();
|
||||
race.setTimeScale(timeScale);
|
||||
//get time scale
|
||||
double timeScale = fp.getTimeScale();
|
||||
race.setTimeScale(timeScale);
|
||||
|
||||
for (Map<String, Object> team : teams) {
|
||||
boatNames.add((String) team.get("team-name"));
|
||||
}
|
||||
for (Map<String, Object> team : teams) {
|
||||
boatNames.add((String) team.get("team-name"));
|
||||
}
|
||||
|
||||
// Shuffle team names
|
||||
long seed = System.nanoTime();
|
||||
Collections.shuffle(boatNames, new Random(seed));
|
||||
// Shuffle team names
|
||||
long seed = System.nanoTime();
|
||||
Collections.shuffle(boatNames, new Random(seed));
|
||||
|
||||
if (numberOfBoats > Array.getLength(boatNames.toArray())){
|
||||
return null;
|
||||
}
|
||||
if (numberOfBoats > Array.getLength(boatNames.toArray())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (int i = 0; i < numberOfBoats; i++) {
|
||||
race.addBoat(new Boat(boatNames.get(i), (Double)(teams.get(i).get("velocity"))));
|
||||
}
|
||||
for (int i = 0; i < numberOfBoats; i++) {
|
||||
race.addBoat(new Boat(boatNames.get(i), (Double) (teams.get(i).get("velocity"))));
|
||||
}
|
||||
|
||||
race.addLeg(new Leg(35, 100, "Start"));
|
||||
race.addLeg(new Leg(10, 300, "Marker 1"));
|
||||
race.addLeg(new Leg(350, 400, "Leeward Gate"));
|
||||
race.addLeg(new Leg(10, 400, "Windward Gate"));
|
||||
race.addLeg(new Leg(35, 100, "Start"));
|
||||
race.addLeg(new Leg(10, 300, "Marker 1"));
|
||||
race.addLeg(new Leg(350, 400, "Leeward Gate"));
|
||||
race.addLeg(new Leg(10, 400, "Windward Gate"));
|
||||
|
||||
Leg finishingLeg = new Leg(10, 400, "Leeward Gate");
|
||||
finishingLeg.setFinishingLeg(true);
|
||||
Leg finishingLeg = new Leg(10, 400, "Leeward Gate");
|
||||
finishingLeg.setFinishingLeg(true);
|
||||
|
||||
race.addLeg(finishingLeg);
|
||||
race.addLeg(finishingLeg);
|
||||
|
||||
return race;
|
||||
}
|
||||
return race;
|
||||
}
|
||||
|
||||
public static void main( String[] args )
|
||||
{
|
||||
Race race = null;
|
||||
public static void main(String[] args) {
|
||||
Race race = null;
|
||||
|
||||
try{
|
||||
race = createRace();
|
||||
}
|
||||
catch (Exception e){
|
||||
System.out.println(e);
|
||||
}
|
||||
try {
|
||||
race = createRace();
|
||||
} catch (Exception e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
// If race was created
|
||||
if (race != null){
|
||||
race.displayStartingBoats();
|
||||
// If race was created
|
||||
if (race != null) {
|
||||
race.displayStartingBoats();
|
||||
|
||||
System.out.println("\n\n");
|
||||
System.out.println("######################");
|
||||
System.out.println("# Live Race Updates ");
|
||||
System.out.println("######################");
|
||||
race.startRace();
|
||||
System.out.println("\n\n");
|
||||
System.out.println("######################");
|
||||
System.out.println("# Live Race Updates ");
|
||||
System.out.println("######################");
|
||||
race.startRace();
|
||||
|
||||
System.out.println("\n\n");
|
||||
System.out.println("######################");
|
||||
System.out.println("# Race Results ");
|
||||
System.out.println("######################");
|
||||
race.showRaceMarkerResults();
|
||||
race.displayFinishingOrder();
|
||||
}
|
||||
else{
|
||||
System.out.println("There was an error creating the race.");
|
||||
}
|
||||
System.out.println("\n\n");
|
||||
System.out.println("######################");
|
||||
System.out.println("# Race Results ");
|
||||
System.out.println("######################");
|
||||
race.showRaceMarkerResults();
|
||||
race.displayFinishingOrder();
|
||||
} else {
|
||||
System.out.println("There was an error creating the race.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user