mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -4,31 +4,31 @@
|
|||||||
<team>
|
<team>
|
||||||
<name>Oracle Team USA</name>
|
<name>Oracle Team USA</name>
|
||||||
<alias>USA</alias>
|
<alias>USA</alias>
|
||||||
<velocity>10.0</velocity>
|
<velocity>30.9</velocity>
|
||||||
</team>
|
</team>
|
||||||
<team>
|
<team>
|
||||||
<name>Artemis Racing</name>
|
<name>Artemis Racing</name>
|
||||||
<alias>ART</alias>
|
<alias>ART</alias>
|
||||||
<velocity>10.0</velocity>
|
<velocity>59.3</velocity>
|
||||||
</team>
|
</team>
|
||||||
<team>
|
<team>
|
||||||
<name>Emirates Team New Zealand</name>
|
<name>Emirates Team New Zealand</name>
|
||||||
<alias>NZL</alias>
|
<alias>NZL</alias>
|
||||||
<velocity>10.0</velocity>
|
<velocity>51.5</velocity>
|
||||||
</team>
|
</team>
|
||||||
<team>
|
<team>
|
||||||
<name>Land Rover BAR</name>
|
<name>Land Rover BAR</name>
|
||||||
<alias>BAR</alias>
|
<alias>BAR</alias>
|
||||||
<velocity>10.0</velocity>
|
<velocity>29.9</velocity>
|
||||||
</team>
|
</team>
|
||||||
<team>
|
<team>
|
||||||
<name>SoftBank Team Japan</name>
|
<name>SoftBank Team Japan</name>
|
||||||
<alias>JAP</alias>
|
<alias>JAP</alias>
|
||||||
<velocity>10.0</velocity>
|
<velocity>99.6</velocity>
|
||||||
</team>
|
</team>
|
||||||
<team>
|
<team>
|
||||||
<name>Groupama Team France</name>
|
<name>Groupama Team France</name>
|
||||||
<alias>FRC</alias>
|
<alias>FRC</alias>
|
||||||
<velocity>10</velocity>
|
<velocity>45.6</velocity>
|
||||||
</team>
|
</team>
|
||||||
</teams>
|
</teams>
|
||||||
@@ -14,9 +14,6 @@ public class App extends Application
|
|||||||
primaryStage.setTitle("RaceVision");
|
primaryStage.setTitle("RaceVision");
|
||||||
primaryStage.setScene(new Scene(root));
|
primaryStage.setScene(new Scene(root));
|
||||||
|
|
||||||
// seng302.models.OldApp.main(); // Run this to show how positions are updated
|
|
||||||
// seng302.controllers.RaceController.initializeRace();
|
|
||||||
|
|
||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ public class CanvasController {
|
|||||||
*/
|
*/
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
gc = canvas.getGraphicsContext2D();
|
gc = canvas.getGraphicsContext2D();
|
||||||
//gc.scale(1, 1);
|
//gc.scale(2, 2);
|
||||||
RaceController raceController = new RaceController();
|
RaceController raceController = new RaceController();
|
||||||
raceController.initializeRace();
|
raceController.initializeRace();
|
||||||
race = raceController.getRace();
|
race = raceController.getRace();
|
||||||
@@ -144,7 +144,7 @@ public class CanvasController {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(long now) {
|
public void handle(long now) {
|
||||||
if (now - lastUpdate >= 16000000){
|
if (now - lastUpdate >= 33000000){
|
||||||
gc.clearRect(0, 0, 19200, 10800);
|
gc.clearRect(0, 0, 19200, 10800);
|
||||||
drawCourse();
|
drawCourse();
|
||||||
drawBoats();
|
drawBoats();
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
package seng302.controllers;
|
package seng302.controllers;
|
||||||
|
|
||||||
import seng302.models.Boat;
|
import seng302.models.Boat;
|
||||||
import seng302.models.OldFileParser;
|
|
||||||
import seng302.models.Race;
|
import seng302.models.Race;
|
||||||
|
import seng302.models.parsers.ConfigParser;
|
||||||
import seng302.models.parsers.CourseParser;
|
import seng302.models.parsers.CourseParser;
|
||||||
|
import seng302.models.parsers.TeamsParser;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -21,11 +20,11 @@ public class RaceController {
|
|||||||
Race race = null;
|
Race race = null;
|
||||||
|
|
||||||
public void initializeRace() {
|
public void initializeRace() {
|
||||||
String raceConfigFile;
|
String raceConfigFile = "doc/examples/config.xml";
|
||||||
raceConfigFile = "doc/examples/config.json";
|
String teamsConfigFile = "doc/examples/teams.xml";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
race = createRace(raceConfigFile);
|
race = createRace(raceConfigFile, teamsConfigFile);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("There was an error creating the race.");
|
System.out.println("There was an error creating the race.");
|
||||||
}
|
}
|
||||||
@@ -37,36 +36,28 @@ public class RaceController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Race createRace(String configFile) throws Exception {
|
public Race createRace(String configFile, String teamsConfigFile) throws Exception {
|
||||||
Race race = new Race();
|
Race race = new Race();
|
||||||
OldFileParser fp;
|
|
||||||
|
|
||||||
// Read team names from file
|
// Read team names from file
|
||||||
try{
|
TeamsParser tp = new TeamsParser(teamsConfigFile);
|
||||||
fp = new OldFileParser(configFile);
|
|
||||||
}
|
// Read course from file
|
||||||
catch (FileNotFoundException e){
|
ConfigParser config = new ConfigParser(configFile);
|
||||||
System.out.println("Config file does not exist");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
ArrayList<String> boatNames = new ArrayList<>();
|
ArrayList<String> boatNames = new ArrayList<>();
|
||||||
ArrayList<Map<String, Object>> teams = fp.getTeams();
|
ArrayList<Boat> teams = tp.getBoats();
|
||||||
|
|
||||||
//get race size
|
//get race size
|
||||||
int numberOfBoats = (int) fp.getRaceSize();
|
int numberOfBoats = teams.size();
|
||||||
int boatsAdded = 0;
|
|
||||||
|
|
||||||
//get time scale
|
//get time scale
|
||||||
double timeScale = fp.getTimeScale();
|
double timeScale = config.getTimeScale();
|
||||||
race.setTimeScale(timeScale);
|
race.setTimeScale(timeScale);
|
||||||
|
|
||||||
for (Map<String, Object> team : teams) {
|
for (Boat boat : teams) {
|
||||||
if (boatsAdded < numberOfBoats){
|
boatNames.add(boat.getTeamName());
|
||||||
boatNames.add((String) team.get("team-name"));
|
race.addBoat(boat);
|
||||||
race.addBoat(new Boat(team.get("team-name").toString(), (Double) (team.get("velocity"))));
|
|
||||||
}
|
|
||||||
boatsAdded++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shuffle team names
|
// Shuffle team names
|
||||||
@@ -77,8 +68,8 @@ public class RaceController {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
CourseParser cp = new CourseParser("doc/examples/course.xml");
|
CourseParser course = new CourseParser("doc/examples/course.xml");
|
||||||
race.addCourse(cp.getCourse());
|
race.addCourse(course.getCourse());
|
||||||
|
|
||||||
return race;
|
return race;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,105 +0,0 @@
|
|||||||
package seng302.models;
|
|
||||||
|
|
||||||
import seng302.models.mark.SingleMark;
|
|
||||||
|
|
||||||
import java.lang.reflect.Array;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
|
|
||||||
public class OldApp {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds a race object for the AC35 course
|
|
||||||
*
|
|
||||||
* @return a Race object for the AC35 course
|
|
||||||
*/
|
|
||||||
public static Race createRace(String configFile) throws Exception {
|
|
||||||
Race race = new Race();
|
|
||||||
OldFileParser fp;
|
|
||||||
|
|
||||||
// Read team names from file
|
|
||||||
try{
|
|
||||||
fp = new OldFileParser(configFile);
|
|
||||||
}
|
|
||||||
catch (FileNotFoundException e){
|
|
||||||
System.out.println("Config file does not exist");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
ArrayList<String> boatNames = new ArrayList<>();
|
|
||||||
ArrayList<Map<String, Object>> teams = fp.getTeams();
|
|
||||||
|
|
||||||
//get race size
|
|
||||||
int numberOfBoats = (int) fp.getRaceSize();
|
|
||||||
|
|
||||||
//get time scale
|
|
||||||
double timeScale = fp.getTimeScale();
|
|
||||||
race.setTimeScale(timeScale);
|
|
||||||
|
|
||||||
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));
|
|
||||||
|
|
||||||
if (numberOfBoats > Array.getLength(boatNames.toArray())) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add boats to the race
|
|
||||||
for (int i = 0; i < numberOfBoats; i++) {
|
|
||||||
race.addBoat(new Boat(boatNames.get(i), (Double) (teams.get(i).get("velocity"))));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add marks to race in order
|
|
||||||
// race.addMark(new SingleMark("Start", 32.296038,-64.854401 ));
|
|
||||||
// race.addMark(new SingleMark("Mid SingleMark", 32.292881,-64.843231 ));
|
|
||||||
// race.addMark(new SingleMark("Leeward Gate", 32.283808,-64.850012 ));
|
|
||||||
// race.addMark(new SingleMark("Windward Gate", 32.309908,-64.833665 ));
|
|
||||||
// race.addMark(new SingleMark("Finish", 32.318439,-64.837367 ));
|
|
||||||
|
|
||||||
return race;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main() {
|
|
||||||
Race race = null;
|
|
||||||
String raceConfigFile;
|
|
||||||
|
|
||||||
raceConfigFile = "doc/examples/config.json";
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
|
||||||
race = createRace(raceConfigFile);
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.out.println("There was an error creating the race.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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("# Race Results ");
|
|
||||||
System.out.println("######################");
|
|
||||||
|
|
||||||
//race.showRaceMarkerResults();
|
|
||||||
//race.displayFinishingOrder();
|
|
||||||
|
|
||||||
} else {
|
|
||||||
System.out.println("There was an error creating the race. Exiting.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,132 +0,0 @@
|
|||||||
package seng302.models;
|
|
||||||
|
|
||||||
import org.json.simple.JSONObject;
|
|
||||||
import org.json.simple.parser.JSONParser;
|
|
||||||
import org.json.simple.parser.ParseException;
|
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read team name from a given Json file. So that user can extract information
|
|
||||||
* efficiently from external files.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class OldFileParser {
|
|
||||||
|
|
||||||
private String filePath;
|
|
||||||
private JSONObject content;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* used to construct an instance of file parser
|
|
||||||
*
|
|
||||||
* @param filePath a string like path to show location of desired file to
|
|
||||||
* be parsed
|
|
||||||
*/
|
|
||||||
public OldFileParser(String filePath) throws Exception {
|
|
||||||
this.filePath = filePath;
|
|
||||||
this.readFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads content from a given file, and return the content as JSONObject.
|
|
||||||
* Throws FileNotFoundException, if the given file cannot be found.
|
|
||||||
*/
|
|
||||||
private void readFile() throws FileNotFoundException {
|
|
||||||
JSONParser parser = new JSONParser();
|
|
||||||
try {
|
|
||||||
this.content = (JSONObject) parser.parse(new FileReader(filePath));
|
|
||||||
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
throw e;
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (ParseException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets time scale setting parameter.
|
|
||||||
*
|
|
||||||
* @return long time scale. -1 if parameter is invalid (eg. scale is
|
|
||||||
* negative number, or containing non numeric character) or cannot be found.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public double getTimeScale() {
|
|
||||||
try {
|
|
||||||
double timeScale = (double) this.content.get("time-scale");
|
|
||||||
return timeScale >= 0 ? timeScale : -1;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets race name in the setting file.
|
|
||||||
*
|
|
||||||
* @return a string of race name. null if race name is invalid or cannot
|
|
||||||
* be found.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public String getRaceName() {
|
|
||||||
try {
|
|
||||||
return (String) this.content.get("race-name");
|
|
||||||
} catch (Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets an array of teams who participate the race.
|
|
||||||
*
|
|
||||||
* @return an ArrayList containing strings of team names. null if teams
|
|
||||||
* setting is invalid or there is no team.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public ArrayList<Map<String, Object>> getTeams() {
|
|
||||||
try {
|
|
||||||
return (ArrayList<Map<String, Object>>) this.content.get("teams");
|
|
||||||
} catch (Exception e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the total number of teams.
|
|
||||||
*
|
|
||||||
* @return the number of teams. 0 if no teams or anything goes wrong.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public long getTotalNumberOfTeams() {
|
|
||||||
ArrayList<Map<String, Object>> teams = getTeams();
|
|
||||||
try {
|
|
||||||
return teams.size();
|
|
||||||
} catch (Exception e) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the number of boats that would compete during a race. Returns the
|
|
||||||
* total number of race size if parameter is invalid or cannot be found.
|
|
||||||
*
|
|
||||||
* @return an int of the race size.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public long getRaceSize() {
|
|
||||||
long totalTeams = this.getTotalNumberOfTeams();
|
|
||||||
try {
|
|
||||||
long raceSize = (long) this.content.get("race-size");
|
|
||||||
return raceSize >= 0 && raceSize <= totalTeams ? raceSize : totalTeams;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return totalTeams;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
package seng302;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import seng302.models.OldFileParser;
|
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unit test for FileParser class
|
|
||||||
* Created by Haoming on 5/03/17.
|
|
||||||
*/
|
|
||||||
public class OldFileParserTest {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* test if it fails from reading non existed file
|
|
||||||
*/
|
|
||||||
@Test(expected = FileNotFoundException.class)
|
|
||||||
public void readNonExistedFile() throws Exception {
|
|
||||||
OldFileParser fileParser = new OldFileParser("test/java/seng302/non-existed.json");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* test a valid json file with valid content.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void readValidFile() throws Exception {
|
|
||||||
OldFileParser fileParser = new OldFileParser("src/test/java/seng302/valid.json");
|
|
||||||
|
|
||||||
assertEquals("AC35", fileParser.getRaceName());
|
|
||||||
|
|
||||||
assertEquals("Oracle Team USA", fileParser.getTeams().get(0).get("team-name"));
|
|
||||||
assertEquals(20.9, fileParser.getTeams().get(0).get("velocity"));
|
|
||||||
assertEquals(2, fileParser.getRaceSize());
|
|
||||||
assertEquals(6, fileParser.getTotalNumberOfTeams());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* test an invalid json file within wrong type value and misnamed
|
|
||||||
* variable name.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void readInvalidFile() throws Exception {
|
|
||||||
OldFileParser fileParser = new OldFileParser("src/test/java/seng302/invalid.json");
|
|
||||||
|
|
||||||
assertEquals(null, fileParser.getRaceName());
|
|
||||||
assertEquals(null, fileParser.getTeams());
|
|
||||||
//assertEquals(-1, fileParser.getTimeScale());
|
|
||||||
assertEquals(null, fileParser.getTeams());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,15 +1,7 @@
|
|||||||
package seng302.controllers;
|
package seng302.controllers;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import seng302.models.Boat;
|
//import static org.mockito.Mockito.when;
|
||||||
import seng302.models.Event;
|
|
||||||
import seng302.models.mark.SingleMark;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by ptg19 on 23/03/17.
|
* Created by ptg19 on 23/03/17.
|
||||||
|
|||||||
Reference in New Issue
Block a user