mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Created canvas and race controllers to display boats on canvas and modified marks and parsers to support them.
#story[377] #pair[zyt10, ptg19]
This commit is contained in:
@@ -12,6 +12,7 @@ import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.util.Duration;
|
||||
import seng302.models.*;
|
||||
import seng302.models.mark.Mark;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -24,14 +25,16 @@ import static java.lang.Math.abs;
|
||||
*/
|
||||
public class CanvasController {
|
||||
@FXML private Canvas canvas;
|
||||
Race race;
|
||||
GraphicsContext gc;
|
||||
|
||||
|
||||
public void initialize() {
|
||||
GraphicsContext gc = canvas.getGraphicsContext2D();
|
||||
gc = canvas.getGraphicsContext2D();
|
||||
gc.scale(5,5);
|
||||
RaceController raceController = new RaceController();
|
||||
raceController.initializeRace();
|
||||
Race race = raceController.getRace();
|
||||
race = raceController.getRace();
|
||||
HashMap<Boat, TimelineInfo> timelineInfos = new HashMap<>();
|
||||
|
||||
HashMap<Boat, List> boat_events = race.getEvents();
|
||||
@@ -60,12 +63,13 @@ public class CanvasController {
|
||||
public void handle(long now) {
|
||||
GraphicsContext gc = canvas.getGraphicsContext2D();
|
||||
gc.clearRect(0,0,760,360);
|
||||
drawCourse();
|
||||
gc.setFill(Color.FORESTGREEN);
|
||||
for (Boat boat: timelineInfos.keySet()){
|
||||
TimelineInfo timelineInfo = timelineInfos.get(boat);
|
||||
// System.out.println(timelineInfo.getX().doubleValue());
|
||||
// System.out.println(timelineInfo.getY().doubleValue());
|
||||
drawBoat(gc, timelineInfo.getX().doubleValue(), timelineInfo.getY().doubleValue(), boat.getColor());
|
||||
drawBoat(timelineInfo.getX().doubleValue(), timelineInfo.getY().doubleValue(), boat.getColor());
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -86,7 +90,7 @@ public class CanvasController {
|
||||
|
||||
}
|
||||
|
||||
private void drawBoat(GraphicsContext gc, double x, double y, Color color) {
|
||||
private void drawBoat(double x, double y, Color color) {
|
||||
x = abs(x - 32.313291) * 1000; // to prevent negative longtitude
|
||||
y = abs(y + 64.887057) * 1000; // to prevent negative latitude
|
||||
|
||||
@@ -95,4 +99,14 @@ public class CanvasController {
|
||||
gc.setFill(color);
|
||||
gc.fillOval(x, y, diameter, diameter);
|
||||
}
|
||||
|
||||
private void drawCourse(){
|
||||
for (Mark mark: race.getCourse()){
|
||||
double x = abs(mark.getLatitude() - 32.313291) * 1000; // to prevent negative longtitude
|
||||
double y = abs(mark.getLongitude() + 64.887057) * 1000; // to prevent negative latitude
|
||||
|
||||
gc.setFill(Color.BLACK);
|
||||
gc.fillOval(x, y, 2, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package seng302.controllers;
|
||||
|
||||
import seng302.models.Boat;
|
||||
import seng302.models.FileParser;
|
||||
import seng302.models.Mark;
|
||||
import seng302.models.OldFileParser;
|
||||
import seng302.models.parsers.*;
|
||||
import seng302.models.mark.*;
|
||||
import seng302.models.Race;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
@@ -38,11 +39,11 @@ public class RaceController {
|
||||
|
||||
public Race createRace(String configFile) throws Exception {
|
||||
Race race = new Race();
|
||||
FileParser fp;
|
||||
OldFileParser fp;
|
||||
|
||||
// Read team names from file
|
||||
try{
|
||||
fp = new FileParser(configFile);
|
||||
fp = new OldFileParser(configFile);
|
||||
}
|
||||
catch (FileNotFoundException e){
|
||||
System.out.println("Config file does not exist");
|
||||
@@ -76,12 +77,8 @@ public class RaceController {
|
||||
race.addBoat(new Boat(boatNames.get(i), (Double) (teams.get(i).get("velocity"))));
|
||||
}
|
||||
|
||||
// Add marks to race in order
|
||||
race.addMark(new Mark("Start", 32.296038,-64.854401 ));
|
||||
race.addMark(new Mark("Mid Mark", 32.292881,-64.843231 ));
|
||||
race.addMark(new Mark("Leeward Gate", 32.283808,-64.850012 ));
|
||||
race.addMark(new Mark("Windward Gate", 32.309908,-64.833665 ));
|
||||
race.addMark(new Mark("Finish", 32.318439,-64.837367 ));
|
||||
CourseParser cp = new CourseParser("doc/examples/course.xml");
|
||||
race.addCourse(cp.getCourse());
|
||||
|
||||
return race;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user