RaceViewController listens to health changes on the local player's boat
#story[1291]
This commit is contained in:
+9
-2
@@ -2,10 +2,12 @@ package visualiser.Commands.VisualiserRaceCommands;
|
||||
|
||||
import mock.model.commandFactory.Command;
|
||||
import network.Messages.BoatState;
|
||||
import shared.exceptions.BoatNotFoundException;
|
||||
import visualiser.model.VisualiserBoat;
|
||||
import visualiser.model.VisualiserRaceState;
|
||||
|
||||
/**
|
||||
* Created by connortaylorbrown on 20/09/17.
|
||||
* Updates boats on visualiser when their health changes
|
||||
*/
|
||||
public class BoatStateCommand implements Command {
|
||||
private BoatState boatState;
|
||||
@@ -18,6 +20,11 @@ public class BoatStateCommand implements Command {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
System.out.println(boatState.getBoatHealth());
|
||||
try {
|
||||
VisualiserBoat boat = visualiserRace.getBoat(boatState.getSourceID());
|
||||
boat.setHealth(boatState.getBoatHealth());
|
||||
} catch (BoatNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,6 +334,11 @@ public class RaceViewController extends Controller {
|
||||
|
||||
boat.legProperty().addListener((o, prev, curr) -> Platform.runLater(() -> swapColours(curr)));
|
||||
boat.hasCollidedProperty().addListener((o, prev, curr) -> Platform.runLater(() -> showCollision(boat, shockwave)));
|
||||
if(boat.getSourceID() == race.getVisualiserRaceState().getPlayerBoatID()) {
|
||||
boat.healthProperty().addListener((o, prev, curr) -> {
|
||||
System.out.println(curr);
|
||||
});
|
||||
}
|
||||
}
|
||||
// Fix initial bird's-eye position
|
||||
view3D.updatePivot(new Translate(250, 0, 210));
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package visualiser.model;
|
||||
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.property.*;
|
||||
import javafx.scene.paint.Color;
|
||||
import network.Messages.Enums.BoatStatusEnum;
|
||||
import shared.model.*;
|
||||
@@ -65,6 +62,7 @@ public class VisualiserBoat extends Boat {
|
||||
private ObjectProperty<GPSCoordinate> positionProperty;
|
||||
private ObjectProperty<Bearing> bearingProperty;
|
||||
private BooleanProperty hasCollided;
|
||||
private IntegerProperty healthProperty;
|
||||
|
||||
|
||||
/**
|
||||
@@ -78,6 +76,7 @@ public class VisualiserBoat extends Boat {
|
||||
|
||||
this.color = color;
|
||||
this.hasCollided = new SimpleBooleanProperty(false);
|
||||
this.healthProperty = new SimpleIntegerProperty(100);
|
||||
}
|
||||
|
||||
|
||||
@@ -281,4 +280,18 @@ public class VisualiserBoat extends Boat {
|
||||
public void setHasCollided(boolean hasCollided) {
|
||||
this.hasCollided.set(hasCollided);
|
||||
}
|
||||
|
||||
public IntegerProperty healthProperty() {
|
||||
return healthProperty;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getHealth() {
|
||||
return healthProperty.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHealth(double healthProperty) {
|
||||
this.healthProperty.set((int)healthProperty);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user