BoatState message can be received from mock by visualiser

- Basic penalties have been made for out of bounds and collisions
- RaceServer packages and sends BoatState messages for each boat
- ServerConnection routes BoatState messages instead of dropping by default
- VisualiserRaceCommandFactory produces BoatStateCommands

#story[1291]
This commit is contained in:
Connor Taylor-Brown
2017-09-20 14:07:50 +12:00
parent a295728e89
commit 50d5dd02a2
9 changed files with 86 additions and 8 deletions
@@ -103,6 +103,11 @@ public class Boat extends Collider {
*/
private boolean isColliding = false;
/**
* Amount of health boat currently has, between 0 and 100
*/
private int health;
/**
* Constructs a boat object with a given sourceID, name, country/team abbreviation, and polars table.
*
@@ -113,6 +118,7 @@ public class Boat extends Collider {
public Boat(int sourceID, String name, String country) {
this.sourceID = sourceID;
this.health = 100;
this.setName(name);
this.setCountry(country);
@@ -419,6 +425,8 @@ public class Boat extends Collider {
@Override
public void onCollisionEnter(Collision e) {
if(e.getBearing().degrees() > 270 || e.getBearing().degrees() < 90) {
// Deplete health
e.getBoat().updateHealth(-5);
// Notify observers of collision
this.setChanged();
notifyObservers(e);
@@ -432,4 +440,22 @@ public class Boat extends Collider {
public void setColliding(boolean colliding) {
isColliding = colliding;
}
public int getHealth() {
return health;
}
public void setHealth(int health) {
this.health = health;
}
/**
* Add a given amount of HP to boat health
* @param delta amount of HP to add
*/
public void updateHealth(int delta) {
health += delta;
if(health < 0) health = 0;
else if(health > 100) health = 100;
}
}
@@ -97,6 +97,7 @@ public class Mark extends Collider{
@Override
public void onCollisionEnter(Collision e) {
e.getBoat().updateHealth(-10);
this.setChanged();
notifyObservers(e);
}