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:
Generated
+3
-17
@@ -1,32 +1,18 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="CompilerConfiguration">
|
<component name="CompilerConfiguration">
|
||||||
<resourceExtensions />
|
|
||||||
<wildcardResourcePatterns>
|
|
||||||
<entry name="!?*.java" />
|
|
||||||
<entry name="!?*.form" />
|
|
||||||
<entry name="!?*.class" />
|
|
||||||
<entry name="!?*.groovy" />
|
|
||||||
<entry name="!?*.scala" />
|
|
||||||
<entry name="!?*.flex" />
|
|
||||||
<entry name="!?*.kt" />
|
|
||||||
<entry name="!?*.clj" />
|
|
||||||
<entry name="!?*.aj" />
|
|
||||||
</wildcardResourcePatterns>
|
|
||||||
<annotationProcessing>
|
<annotationProcessing>
|
||||||
<profile default="true" name="Default" enabled="false">
|
<profile name="Maven default annotation processors profile" enabled="true">
|
||||||
<processorPath useClasspath="true" />
|
|
||||||
</profile>
|
|
||||||
<profile default="false" name="Maven default annotation processors profile" enabled="true">
|
|
||||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
<outputRelativeToContentRoot value="true" />
|
<outputRelativeToContentRoot value="true" />
|
||||||
<processorPath useClasspath="true" />
|
|
||||||
<module name="app" />
|
<module name="app" />
|
||||||
|
<module name="team-7" />
|
||||||
</profile>
|
</profile>
|
||||||
</annotationProcessing>
|
</annotationProcessing>
|
||||||
<bytecodeTargetLevel>
|
<bytecodeTargetLevel>
|
||||||
<module name="app" target="1.8" />
|
<module name="app" target="1.8" />
|
||||||
|
<module name="team-7" target="1.8" />
|
||||||
</bytecodeTargetLevel>
|
</bytecodeTargetLevel>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
Generated
+1
@@ -3,6 +3,7 @@
|
|||||||
<component name="ProjectModuleManager">
|
<component name="ProjectModuleManager">
|
||||||
<modules>
|
<modules>
|
||||||
<module fileurl="file://$PROJECT_DIR$/app.iml" filepath="$PROJECT_DIR$/app.iml" />
|
<module fileurl="file://$PROJECT_DIR$/app.iml" filepath="$PROJECT_DIR$/app.iml" />
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/team-7.iml" filepath="$PROJECT_DIR$/.idea/team-7.iml" />
|
||||||
</modules>
|
</modules>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -8,21 +8,21 @@ import java.util.Collections;
|
|||||||
public class ConstantVelocityRace extends Race {
|
public class ConstantVelocityRace extends Race {
|
||||||
/**
|
/**
|
||||||
* Initialiser for a Race with constant velocity.
|
* 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 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
|
* @param timescale integer that the race is at timescale = 1000ms
|
||||||
* @see seng302.Boat
|
* @see seng302.Boat
|
||||||
* @see seng302.RaceMarker
|
* @see seng302.RaceMarker
|
||||||
*/
|
*/
|
||||||
public ConstantVelocityRace(Boat[] boats, RaceMarker[] marks, int timescale) {
|
public ConstantVelocityRace(Boat[] startingBoats, RaceMarker[] marks, int timescale) {
|
||||||
super(boats, marks, timescale);
|
super(startingBoats, marks, timescale);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the Race with respects to boat speed.
|
* Generates the Race with respects to boat speed.
|
||||||
*/
|
*/
|
||||||
protected void generateRace() {
|
protected void generateRace() {
|
||||||
for(Boat boat : boats) {
|
for(Boat boat : startingBoats) {
|
||||||
for(int i = 0; i < marks.length; i++) {
|
for(int i = 0; i < marks.length; i++) {
|
||||||
RaceMarker raceMarker = marks[i];
|
RaceMarker raceMarker = marks[i];
|
||||||
if (i != marks.length - 1) {
|
if (i != marks.length - 1) {
|
||||||
|
|||||||
@@ -8,12 +8,14 @@ import java.util.*;
|
|||||||
* Created by fwy13 on 3/03/17.
|
* Created by fwy13 on 3/03/17.
|
||||||
*/
|
*/
|
||||||
public abstract class Race {
|
public abstract class Race {
|
||||||
protected Boat[] boats;
|
protected Boat[] startingBoats;
|
||||||
|
protected ArrayList<Boat> finishingBoats = new ArrayList<>();
|
||||||
protected RaceMarker[] marks;
|
protected RaceMarker[] marks;
|
||||||
protected int timescale = 1000;
|
protected int timescale = 1000;
|
||||||
|
|
||||||
protected LinkedList<Event> events = new LinkedList<Event>();
|
protected LinkedList<Event> events = new LinkedList<Event>();
|
||||||
protected Timer timer = new Timer();
|
protected Timer timer = new Timer();
|
||||||
|
private int SLEEP_TIME = 1000; //time in milliseconds to pause in a paced loop
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initailiser for Race
|
* Initailiser for Race
|
||||||
@@ -22,7 +24,7 @@ public abstract class Race {
|
|||||||
* @param timescale Number or milliseconds that = 1000ms.
|
* @param timescale Number or milliseconds that = 1000ms.
|
||||||
*/
|
*/
|
||||||
public Race(Boat[] boats, RaceMarker[] marks, int timescale) {
|
public Race(Boat[] boats, RaceMarker[] marks, int timescale) {
|
||||||
this.boats = boats;
|
this.startingBoats = boats;
|
||||||
this.marks = marks;
|
this.marks = marks;
|
||||||
this.timescale = timescale;
|
this.timescale = timescale;
|
||||||
generateRace();
|
generateRace();
|
||||||
@@ -36,13 +38,37 @@ public abstract class Race {
|
|||||||
//show the boats participating.
|
//show the boats participating.
|
||||||
System.out.println("Boats Participating:");
|
System.out.println("Boats Participating:");
|
||||||
System.out.println("====================");
|
System.out.println("====================");
|
||||||
for (int i = 0; i < boats.length; i ++){
|
for (int i = 0; i < startingBoats.length; i ++){
|
||||||
System.out.println(i + 1 + ". " + boats[i].getName() + ", Speed: " + Math.round(boats[i].getVelocity() * 1.94384) + "kn");
|
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("\nRace Events:");
|
||||||
System.out.println("============");
|
System.out.println("============");
|
||||||
//show all the events that happen in the race
|
//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) {
|
for (Event event: events) {
|
||||||
timer.schedule(new TimerTask(){
|
timer.schedule(new TimerTask(){
|
||||||
@Override
|
@Override
|
||||||
@@ -73,6 +99,12 @@ public abstract class Race {
|
|||||||
}, (events.getLast().getTime() + 1) * timescale);
|
}, (events.getLast().getTime() + 1) * timescale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void checkPosition() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function is a function that generates the Race and populates the events list.
|
* 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.
|
* Is automatically called by the initialiser function, so that simulateRace() does not return an empty race.
|
||||||
|
|||||||
Reference in New Issue
Block a user