Started merging team 8 paced loop into team 7 codebase.
-No running! Syntax errors and not done merging -Just pushing so David can pull changes #pair[zwu18, esa46]
This commit is contained in:
@@ -8,21 +8,21 @@ import java.util.Collections;
|
||||
public class ConstantVelocityRace extends Race {
|
||||
/**
|
||||
* Initialiser for a Race with constant velocity.
|
||||
* @param boats array of boats
|
||||
* @param startingBoats array of boats
|
||||
* @param marks array of RaceMarkers that the boats need to pass in order to finish the course.
|
||||
* @param timescale integer that the race is at timescale = 1000ms
|
||||
* @see seng302.Boat
|
||||
* @see seng302.RaceMarker
|
||||
*/
|
||||
public ConstantVelocityRace(Boat[] boats, RaceMarker[] marks, int timescale) {
|
||||
super(boats, marks, timescale);
|
||||
public ConstantVelocityRace(Boat[] startingBoats, RaceMarker[] marks, int timescale) {
|
||||
super(startingBoats, marks, timescale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the Race with respects to boat speed.
|
||||
*/
|
||||
protected void generateRace() {
|
||||
for(Boat boat : boats) {
|
||||
for(Boat boat : startingBoats) {
|
||||
for(int i = 0; i < marks.length; i++) {
|
||||
RaceMarker raceMarker = marks[i];
|
||||
if (i != marks.length - 1) {
|
||||
|
||||
@@ -8,12 +8,14 @@ import java.util.*;
|
||||
* Created by fwy13 on 3/03/17.
|
||||
*/
|
||||
public abstract class Race {
|
||||
protected Boat[] boats;
|
||||
protected Boat[] startingBoats;
|
||||
protected ArrayList<Boat> finishingBoats = new ArrayList<>();
|
||||
protected RaceMarker[] marks;
|
||||
protected int timescale = 1000;
|
||||
|
||||
protected LinkedList<Event> events = new LinkedList<Event>();
|
||||
protected Timer timer = new Timer();
|
||||
private int SLEEP_TIME = 1000; //time in milliseconds to pause in a paced loop
|
||||
|
||||
/**
|
||||
* Initailiser for Race
|
||||
@@ -22,7 +24,7 @@ public abstract class Race {
|
||||
* @param timescale Number or milliseconds that = 1000ms.
|
||||
*/
|
||||
public Race(Boat[] boats, RaceMarker[] marks, int timescale) {
|
||||
this.boats = boats;
|
||||
this.startingBoats = boats;
|
||||
this.marks = marks;
|
||||
this.timescale = timescale;
|
||||
generateRace();
|
||||
@@ -36,13 +38,37 @@ public abstract class Race {
|
||||
//show the boats participating.
|
||||
System.out.println("Boats Participating:");
|
||||
System.out.println("====================");
|
||||
for (int i = 0; i < boats.length; i ++){
|
||||
System.out.println(i + 1 + ". " + boats[i].getName() + ", Speed: " + Math.round(boats[i].getVelocity() * 1.94384) + "kn");
|
||||
for (int i = 0; i < startingBoats.length; i ++){
|
||||
System.out.println(i + 1 + ". " + startingBoats[i].getName() + ", Speed: " + Math.round(startingBoats[i].getVelocity() * 1.94384) + "kn");
|
||||
}
|
||||
|
||||
System.out.println("\nRace Events:");
|
||||
System.out.println("============");
|
||||
//show all the events that happen in the race
|
||||
|
||||
long timeStarted = System.currentTimeMillis();
|
||||
long timeElapsed;
|
||||
|
||||
long timeLoopStarted;
|
||||
long timeLoopEnded;
|
||||
|
||||
while (finishingBoats.size() < startingBoats.length) {
|
||||
timeLoopStarted = System.currentTimeMillis();
|
||||
timeElapsed = System.currentTimeMillis() - timeStarted;
|
||||
for (Boat boat : startingBoats) {
|
||||
checkPosition(boat, timeElapsed);
|
||||
}
|
||||
try {
|
||||
timeLoopEnded = System.currentTimeMillis();
|
||||
Thread.sleep(SLEEP_TIME - (timeLoopEnded - timeLoopStarted));
|
||||
} catch (InterruptedException e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
for (Event event: events) {
|
||||
timer.schedule(new TimerTask(){
|
||||
@Override
|
||||
@@ -73,6 +99,12 @@ public abstract class Race {
|
||||
}, (events.getLast().getTime() + 1) * timescale);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void checkPosition() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is a function that generates the Race and populates the events list.
|
||||
* Is automatically called by the initialiser function, so that simulateRace() does not return an empty race.
|
||||
|
||||
Reference in New Issue
Block a user