mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Fixed some bugs
/#pair[hyi25, mra106]
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"race-name": "AC35",
|
"race-name": "AC35",
|
||||||
"time-scale": 100,
|
"time-scale": 1000,
|
||||||
"race-size": 2,
|
"race-size": 4,
|
||||||
"teams": [
|
"teams": [
|
||||||
{"team-name": "Oracle Team USA", "velocity": 20.9},
|
{"team-name": "Oracle Team USA", "velocity": 20.9},
|
||||||
{"team-name": "Artemis Racing", "velocity": 18.3},
|
{"team-name": "Artemis Racing", "velocity": 18.3},
|
||||||
|
|||||||
@@ -7,10 +7,8 @@ public class App
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Builds a race object for the AC35 course
|
* Builds a race object for the AC35 course
|
||||||
*
|
|
||||||
* @param numberOfBoats, the number of boats to include in the race
|
|
||||||
*/
|
*/
|
||||||
public static Race createRace(int numberOfBoats) throws Exception{
|
public static Race createRace() throws Exception{
|
||||||
Race race = new Race();
|
Race race = new Race();
|
||||||
|
|
||||||
// Read team names from file
|
// Read team names from file
|
||||||
@@ -18,6 +16,13 @@ public class App
|
|||||||
ArrayList<String> boatNames = new ArrayList<>();
|
ArrayList<String> boatNames = new ArrayList<>();
|
||||||
ArrayList<Map<String, Object>> teams = fp.getTeams();
|
ArrayList<Map<String, Object>> teams = fp.getTeams();
|
||||||
|
|
||||||
|
//get race size
|
||||||
|
int numberOfBoats = (int) fp.getRaceSize();
|
||||||
|
|
||||||
|
//get time scale
|
||||||
|
int timeScale = (int) fp.getTimeScale();
|
||||||
|
race.setTimeScale(timeScale);
|
||||||
|
|
||||||
for (Map<String, Object> team : teams) {
|
for (Map<String, Object> team : teams) {
|
||||||
boatNames.add((String) team.get("team-name"));
|
boatNames.add((String) team.get("team-name"));
|
||||||
}
|
}
|
||||||
@@ -52,7 +57,7 @@ public class App
|
|||||||
Race race = null;
|
Race race = null;
|
||||||
|
|
||||||
try{
|
try{
|
||||||
race = createRace(2);
|
race = createRace();
|
||||||
}
|
}
|
||||||
catch (Exception e){
|
catch (Exception e){
|
||||||
System.out.println(e);
|
System.out.println(e);
|
||||||
|
|||||||
@@ -135,6 +135,14 @@ public class Race {
|
|||||||
return this.legs;
|
return this.legs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets time scale
|
||||||
|
* @param timeScale
|
||||||
|
*/
|
||||||
|
public void setTimeScale(int timeScale) {
|
||||||
|
this.timeScale = timeScale;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Temporary method used to generated all the events.
|
* Temporary method used to generated all the events.
|
||||||
*/
|
*/
|
||||||
@@ -144,7 +152,7 @@ public class Race {
|
|||||||
for (Boat boat : this.boats) {
|
for (Boat boat : this.boats) {
|
||||||
long totalDistance = 0;
|
long totalDistance = 0;
|
||||||
for (Leg leg : this.legs) {
|
for (Leg leg : this.legs) {
|
||||||
long time = (long) (1000 * totalDistance / (boat.getVelocity() * this.timeScale));
|
long time = (long) (1000 * totalDistance / boat.getVelocity());
|
||||||
Event event = new Event(time, boat, leg);
|
Event event = new Event(time, boat, leg);
|
||||||
events.add(event);
|
events.add(event);
|
||||||
totalDistance += leg.getDistance();
|
totalDistance += leg.getDistance();
|
||||||
@@ -173,7 +181,7 @@ public class Race {
|
|||||||
// iterates all events. ends when no event in events.
|
// iterates all events. ends when no event in events.
|
||||||
while (!events.isEmpty()) {
|
while (!events.isEmpty()) {
|
||||||
Event peekEvent = events.peek();
|
Event peekEvent = events.peek();
|
||||||
long currentTime = System.currentTimeMillis() - this.startTime;
|
long currentTime = (System.currentTimeMillis() - this.startTime) * this.timeScale;
|
||||||
|
|
||||||
if (currentTime > peekEvent.getTime()) {
|
if (currentTime > peekEvent.getTime()) {
|
||||||
// pull out the event
|
// pull out the event
|
||||||
|
|||||||
Reference in New Issue
Block a user