Display list of finishers after race ends.
This commit is contained in:
@@ -1,33 +1,26 @@
|
|||||||
package seng302;
|
package seng302;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
|
|
||||||
public class App
|
public class App
|
||||||
{
|
{
|
||||||
public static void main( String[] args )
|
public static void main( String[] args )
|
||||||
{
|
{
|
||||||
LinkedList<Integer> test = new LinkedList<>();
|
Boat[] boats = {
|
||||||
test.add(5);
|
new Boat("ORACLE TEAM USA", 10),
|
||||||
test.add(1, 8);
|
new Boat("Artemis Racing", 8),
|
||||||
|
new Boat("Emirates Team New Zealand", 12),
|
||||||
|
new Boat("Groupama Team France", 11),
|
||||||
|
new Boat("Land Rover BAR", 10),
|
||||||
|
new Boat("SoftBank Team Japan", 9)
|
||||||
|
};
|
||||||
|
|
||||||
Boat boat1 = new Boat("ORACLE TEAM USA", 10);
|
RaceMarker[] marks = {
|
||||||
Boat boat2 = new Boat("Artemis Racing", 8);
|
new RaceMarker("Start", 0, 0, 59),
|
||||||
Boat boat3 = new Boat("Emirates Team New Zealand", 12);
|
new RaceMarker("Mark", 72, 72, 50),
|
||||||
Boat boat4 = new Boat("Groupama Team France", 11);
|
new RaceMarker("Leeward Gate", 193, 126, 158),
|
||||||
Boat boat5 = new Boat("Land Rover BAR", 10);
|
new RaceMarker("Windward Gate", 373, 41, 0),
|
||||||
Boat boat6 = new Boat("SoftBank Team Japan", 9);
|
new RaceMarker("Leeward Gate", 553, 126, 158),
|
||||||
|
new RaceMarker("Finish", 607, 95, 203)
|
||||||
RaceMarker mark1 = new RaceMarker("Start", 0, 0, 59);
|
};
|
||||||
RaceMarker mark2 = new RaceMarker("Mark", 72, 72, 50);
|
|
||||||
RaceMarker mark3 = new RaceMarker("Leeward Gate", 193, 126, 158);
|
|
||||||
RaceMarker mark4 = new RaceMarker("Windward Gate", 373, 41, 0);
|
|
||||||
RaceMarker mark5 = new RaceMarker("Leeward Gate", 553, 126, 158);
|
|
||||||
RaceMarker mark6 = new RaceMarker("Finish", 607, 95, 203);
|
|
||||||
|
|
||||||
Boat[] boats = {boat1, boat2, boat3, boat4, boat5, boat6};
|
|
||||||
RaceMarker[] marks = {mark1, mark2, mark3, mark4, mark5, mark6};
|
|
||||||
|
|
||||||
Race race = new ConstantVelocityRace(boats, marks);
|
Race race = new ConstantVelocityRace(boats, marks);
|
||||||
race.simulateRace();
|
race.simulateRace();
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
package seng302;
|
package seng302;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by fwy13 on 3/03/17.
|
* Created by fwy13 on 3/03/17.
|
||||||
*/
|
*/
|
||||||
@@ -27,11 +23,19 @@ public class Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public double calculateHeading(){
|
public double calculateHeading(){
|
||||||
//to be changed to cooridinates when used to match reality.
|
//to be changed to coordinates when used to match reality.
|
||||||
double thetaHat = Math.atan2((goalMarker.getLatitude() - raceMarker.getLatitude()), (goalMarker.getLongitude() - raceMarker.getLongitude()));
|
double thetaHat = Math.atan2((goalMarker.getLatitude() - raceMarker.getLatitude()), (goalMarker.getLongitude() - raceMarker.getLongitude()));
|
||||||
return thetaHat >= 0 ? Math.toDegrees(thetaHat): Math.toDegrees(thetaHat + 2 * Math.PI);
|
return thetaHat >= 0 ? Math.toDegrees(thetaHat): Math.toDegrees(thetaHat + 2 * Math.PI);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RaceMarker getRaceMarker() {
|
||||||
|
return raceMarker;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boat getBoat() {
|
||||||
|
return boat;
|
||||||
|
}
|
||||||
|
|
||||||
public void setTime(int time){
|
public void setTime(int time){
|
||||||
this.time = time;
|
this.time = time;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ public class Race {
|
|||||||
Boat[] boats;
|
Boat[] boats;
|
||||||
RaceMarker[] marks;
|
RaceMarker[] marks;
|
||||||
LinkedList<Event> events = new LinkedList<Event>();
|
LinkedList<Event> events = new LinkedList<Event>();
|
||||||
|
Timer timer = new Timer();
|
||||||
|
|
||||||
public Race(Boat[] boats, RaceMarker[] marks){
|
public Race(Boat[] boats, RaceMarker[] marks){
|
||||||
this.boats = boats;
|
this.boats = boats;
|
||||||
@@ -18,24 +19,43 @@ public class Race {
|
|||||||
|
|
||||||
public void simulateRace(){
|
public void simulateRace(){
|
||||||
//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 < boats.length; i ++){
|
||||||
System.out.println(i + 1 + ". " + boats[i].getName() + ", Speed: " + Math.round(boats[i].getVelocity() * 1.94384) + "kn");
|
System.out.println(i + 1 + ". " + boats[i].getName() + ", Speed: " + Math.round(boats[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
|
||||||
for (Event event: events) {
|
for (Event event: events) {
|
||||||
Timer timer = new Timer();
|
|
||||||
timer.schedule(new TimerTask(){
|
timer.schedule(new TimerTask(){
|
||||||
@Override
|
@Override
|
||||||
public void run(){
|
public void run(){
|
||||||
System.out.println(event);
|
System.out.println(event);
|
||||||
}
|
}
|
||||||
}, event.getTime() * 100);
|
}, event.getTime() * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
As the event readout is scheduled, the list of finishers must be
|
||||||
|
displayed afterwards, without the use of threading.
|
||||||
|
*/
|
||||||
|
timer.schedule(new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
System.out.println("\nFinish:");
|
||||||
|
System.out.println("=======");
|
||||||
|
// Print the list of finishers with their placing and time
|
||||||
|
int place = 1;
|
||||||
|
for(Event event: events) {
|
||||||
|
if(event.getRaceMarker().getName().equals("Finish")) {
|
||||||
|
System.out.println(place + ". " + event.getBoat() + " (" + event.getTime() + "s)");
|
||||||
|
place++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, (events.getLast().getTime() + 1) * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ public class RaceMarker {
|
|||||||
this.longitude = longitude;
|
this.longitude = longitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
public double getDistance() {
|
public double getDistance() {
|
||||||
return distance;
|
return distance;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user