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.
130 lines
4.5 KiB
130 lines
4.5 KiB
package seng302.Controllers;
|
|
|
|
|
|
import javafx.beans.property.ReadOnlyObjectWrapper;
|
|
import javafx.beans.value.ObservableValue;
|
|
import javafx.collections.FXCollections;
|
|
import javafx.collections.ObservableList;
|
|
import javafx.fxml.FXML;
|
|
import javafx.scene.canvas.GraphicsContext;
|
|
import javafx.scene.control.TableColumn;
|
|
import javafx.scene.control.TableView;
|
|
import javafx.scene.control.cell.PropertyValueFactory;
|
|
import javafx.scene.layout.AnchorPane;
|
|
import javafx.scene.paint.Color;
|
|
import javafx.util.Callback;
|
|
import org.geotools.referencing.GeodeticCalculator;
|
|
import seng302.Constants;
|
|
import seng302.GPSCoordinate;
|
|
import seng302.Model.ResizableRaceCanvas;
|
|
import seng302.Model.*;
|
|
import seng302.RaceMap;
|
|
|
|
import java.awt.geom.Point2D;
|
|
import java.net.URL;
|
|
import java.util.ArrayList;
|
|
import java.util.ResourceBundle;
|
|
|
|
/**
|
|
* Created by fwy13 on 15/03/2017.
|
|
*/
|
|
public class RaceController extends Controller{
|
|
@FXML
|
|
AnchorPane canvasBase;
|
|
|
|
ResizableRaceCanvas raceMap;
|
|
|
|
@FXML
|
|
TableView boatInfoTable;
|
|
@FXML
|
|
TableColumn<BoatInRace, String> boatPlacingColumn;
|
|
@FXML
|
|
TableColumn<BoatInRace, String> boatTeamColumn;
|
|
@FXML
|
|
TableColumn<BoatInRace, String> boatMarkColumn;
|
|
|
|
/**
|
|
* updates the ResizableRaceCanvas (raceMap) with most recent data
|
|
* @param boats boats that are to be displayed in the race
|
|
* @see ResizableRaceCanvas
|
|
*/
|
|
public void updateMap(ObservableList<BoatInRace> boats) {
|
|
BoatInRace[] boatInRaces = new BoatInRace[boats.size()];
|
|
raceMap.setBoats(boats.toArray(boatInRaces));
|
|
raceMap.drawRaceMap();
|
|
|
|
}
|
|
|
|
/**
|
|
* Updates the array listened by the TableView (boatInfoTable) that displays the boat information.
|
|
* @param race Race to listen to.
|
|
*/
|
|
public void updateInfoTable(Race race) {
|
|
boatInfoTable.getItems().clear();
|
|
boatInfoTable.setItems(race.getStartingBoats());
|
|
|
|
boatTeamColumn.setCellValueFactory(new PropertyValueFactory<BoatInRace,String>("Name"));
|
|
boatMarkColumn.setCellValueFactory(new PropertyValueFactory<BoatInRace, String>("CurrentLeg"));
|
|
boatPlacingColumn.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<BoatInRace, String>, ObservableValue<String>>() {
|
|
@Override
|
|
public ObservableValue<String> call(TableColumn.CellDataFeatures<BoatInRace, String> table) {
|
|
return new ReadOnlyObjectWrapper(boatInfoTable.getItems().indexOf(table.getValue()) + 1);
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override
|
|
public void initialize(URL location, ResourceBundle resources) {
|
|
|
|
BoatInRace[] boats = generateAC35Competitors();
|
|
|
|
raceMap = new ResizableRaceCanvas();
|
|
raceMap.widthProperty().bind(canvasBase.widthProperty());
|
|
raceMap.heightProperty().bind(canvasBase.heightProperty());
|
|
raceMap.setBoats(boats);
|
|
raceMap.drawRaceMap();
|
|
|
|
canvasBase.getChildren().add(raceMap);
|
|
|
|
ArrayList<Leg> legs = generateBermudaCourseLegs();
|
|
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, this);
|
|
|
|
(new Thread(race)).start();
|
|
}
|
|
|
|
/**
|
|
* Function for the Bermuda Race.
|
|
* @return legs in the Bermuda Race.
|
|
*/
|
|
private ArrayList<Leg> generateBermudaCourseLegs() {
|
|
ArrayList<Leg> legs = new ArrayList<>();
|
|
|
|
Leg leg1 = new Leg("Start to Mark 1", Constants.startLineMarker1, Constants.mark1, 0);
|
|
Leg leg2 = new Leg("Mark 1 to Leeward Gate", Constants.mark1, Constants.leewardGate1, 1);
|
|
Leg leg3 = new Leg("Leeward Gate to Windward Gate", Constants.leewardGate1, Constants.windwardGate1, 2);
|
|
Leg leg4 = new Leg("Windward Gate to Leeward Gate", Constants.windwardGate1, Constants.leewardGate1, 3);
|
|
Leg leg5 = new Leg("Leeward Gate to Finish", Constants.leewardGate1, Constants.finishLineMarker1, 4);
|
|
legs.add(leg1); legs.add(leg2); legs.add(leg3); legs.add(leg4); legs.add(leg5);
|
|
return legs;
|
|
}
|
|
|
|
private BoatInRace[] generateAC35Competitors() {
|
|
|
|
BoatInRace boat1 = new BoatInRace("NZ", 500);
|
|
boat1.setColour(Color.DARKVIOLET);
|
|
boat1.setCurrentPosition(new GPSCoordinate(0, 0));
|
|
|
|
BoatInRace boat2 = new BoatInRace("TEST", 400);
|
|
boat2.setColour(Color.DARKRED);
|
|
boat2.setCurrentPosition(new GPSCoordinate(0, 0));
|
|
|
|
BoatInRace boat3 = new BoatInRace("TEST2", 350);
|
|
boat3.setColour(Color.FUCHSIA);
|
|
boat3.setCurrentPosition(new GPSCoordinate(0, 0));
|
|
return new BoatInRace[] {boat1, boat2, boat3};
|
|
|
|
}
|
|
|
|
|
|
}
|