RaceController can now set up collision listeners on each boat.

#story[1195]
main
Connor Taylor-Brown 8 years ago
parent e354320d74
commit f2370485a0

@ -3,6 +3,8 @@ package visualiser.Commands.VisualiserRaceCommands;
import javafx.scene.media.AudioClip; import javafx.scene.media.AudioClip;
import mock.model.commandFactory.Command; import mock.model.commandFactory.Command;
import network.Messages.YachtEvent; import network.Messages.YachtEvent;
import shared.exceptions.BoatNotFoundException;
import visualiser.model.VisualiserBoat;
import visualiser.model.VisualiserRaceState; import visualiser.model.VisualiserRaceState;
/** /**
@ -34,6 +36,11 @@ public class BoatCollisionCommand implements Command {
sound.play(); sound.play();
} }
//System.out.println("Collision command executed!"); try {
VisualiserBoat boat = visualiserRace.getBoat(yachtEvent.getSourceID());
boat.setHasCollided(true);
} catch (BoatNotFoundException e) {
e.printStackTrace();
}
} }
} }

@ -311,6 +311,7 @@ public class RaceController extends Controller {
} }
boat.legProperty().addListener((o, prev, curr) -> swapColours(curr)); boat.legProperty().addListener((o, prev, curr) -> swapColours(curr));
boat.hasCollidedProperty().addListener((o, prev, curr) -> showCollision(boat));
} }
// Fix initial bird's-eye position // Fix initial bird's-eye position
view3D.updatePivot(new Translate(250, 0, 210)); view3D.updatePivot(new Translate(250, 0, 210));
@ -368,6 +369,10 @@ public class RaceController extends Controller {
}); });
} }
private void showCollision(VisualiserBoat boat) {
System.out.println(boat.getSourceID() + " has collided");
}
private void addThirdPersonAnnotations(Subject3D subject3D) { private void addThirdPersonAnnotations(Subject3D subject3D) {
viewSubjects.add(nextMarkArrow); viewSubjects.add(nextMarkArrow);

@ -1,6 +1,8 @@
package visualiser.model; package visualiser.model;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ObjectProperty; import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleObjectProperty;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import network.Messages.Enums.BoatStatusEnum; import network.Messages.Enums.BoatStatusEnum;
@ -62,6 +64,7 @@ public class VisualiserBoat extends Boat {
private ObjectProperty<GPSCoordinate> positionProperty; private ObjectProperty<GPSCoordinate> positionProperty;
private ObjectProperty<Bearing> bearingProperty; private ObjectProperty<Bearing> bearingProperty;
private BooleanProperty hasCollided;
/** /**
@ -74,6 +77,7 @@ public class VisualiserBoat extends Boat {
super(boat.getSourceID(), boat.getName(), boat.getCountry()); super(boat.getSourceID(), boat.getName(), boat.getCountry());
this.color = color; this.color = color;
this.hasCollided = new SimpleBooleanProperty(false);
} }
@ -253,10 +257,6 @@ public class VisualiserBoat extends Boat {
this.positionProperty.set(position); this.positionProperty.set(position);
} }
public ObjectProperty<GPSCoordinate> positionProperty() {
return positionProperty;
}
@Override @Override
public Bearing getBearing() { public Bearing getBearing() {
return bearingProperty.get(); return bearingProperty.get();
@ -270,7 +270,15 @@ public class VisualiserBoat extends Boat {
this.bearingProperty.set(bearing); this.bearingProperty.set(bearing);
} }
public ObjectProperty<Bearing> bearingProperty() { public boolean hasCollided() {
return bearingProperty; return hasCollided.get();
}
public BooleanProperty hasCollidedProperty() {
return hasCollided;
}
public void setHasCollided(boolean hasCollided) {
this.hasCollided.set(hasCollided);
} }
} }

Loading…
Cancel
Save