You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.2 KiB
47 lines
1.2 KiB
package seng302;
|
|
|
|
|
|
import java.util.*;
|
|
|
|
/**
|
|
* Created by fwy13 on 3/03/17.
|
|
*/
|
|
public class Race {
|
|
Boat[] boats;
|
|
LinkedList<Event> events = new LinkedList<Event>();
|
|
|
|
public Race(Boat[] boats){
|
|
this.boats = boats;
|
|
}
|
|
|
|
public void simulateRace(){
|
|
String[] marks = {"Mark", "Leeward Gate", "Windward Gate", "Leeward Gate", "Finish"};
|
|
randomiseRace(marks);
|
|
//printRace();
|
|
for (Event event: events) {
|
|
Timer timer = new Timer();
|
|
timer.schedule(new TimerTask(){
|
|
@Override
|
|
public void run(){
|
|
System.out.println(event);
|
|
}
|
|
}, event.getTime() * 1000);
|
|
}
|
|
}
|
|
|
|
public void randomiseRace(String[] eventNames){
|
|
Random rand = new Random();
|
|
for (Boat boat: this.boats){
|
|
events.add(new Event("Start", boat, 0));
|
|
int prevTime = 0;
|
|
for (String markName: eventNames){
|
|
int time = rand.nextInt(12) + 6;
|
|
events.add(new Event(markName, boat, prevTime + time));
|
|
prevTime += time;
|
|
}
|
|
}
|
|
Collections.sort(events, (o1, o2) -> o1.getTime() - o2.getTime());
|
|
}
|
|
|
|
}
|