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]
main
Erika Savell 9 years ago
parent a7c64dc401
commit 41cdf09dc2

@ -1,32 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<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>
<profile default="true" name="Default" enabled="false">
<processorPath useClasspath="true" />
</profile>
<profile default="false" name="Maven default annotation processors profile" enabled="true">
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<processorPath useClasspath="true" />
<module name="app" />
<module name="team-7" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
<module name="app" target="1.8" />
<module name="team-7" target="1.8" />
</bytecodeTargetLevel>
</component>
</project>

@ -3,6 +3,7 @@
<component name="ProjectModuleManager">
<modules>
<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>
</component>
</project>

@ -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.

Loading…
Cancel
Save