Skip to content
Snippets Groups Projects
Commit 61496cc6 authored by keyno10's avatar keyno10
Browse files

Healing & damage completed

parent 75bced6d
No related branches found
No related tags found
No related merge requests found
package Character;
import Listeners.HealthChangeListener;
import javafx.beans.property.SimpleIntegerProperty;
import java.util.ArrayList;
......@@ -8,6 +9,7 @@ import java.util.Collections;
public class Health {
private final ArrayList<Integer> healthBoxes = new ArrayList<>();
private SimpleIntegerProperty numberOfHealth = new SimpleIntegerProperty(0);
private final ArrayList<HealthChangeListener> healthChangeListeners = new ArrayList<>();
private int bashing = 0;
private int lethal = 0;
......@@ -50,6 +52,7 @@ public class Health {
healthBoxes.add(box);
}
sort();
notifyListeners();
}
/**
......@@ -72,6 +75,7 @@ public class Health {
if(agg > numberOfHealth.get()) {
aggDamage(0);
}
notifyListeners();
}
/**
......@@ -87,6 +91,7 @@ public class Health {
bashing = 0;
}
}
notifyListeners();
}
/**
......@@ -105,6 +110,7 @@ public class Health {
if(bashing < lethal) {
bashing = lethal;
}
notifyListeners();
}
/**
......@@ -123,6 +129,7 @@ public class Health {
if(lethal < agg) {
lethal = agg;
}
notifyListeners();
}
/**
......@@ -150,4 +157,20 @@ public class Health {
public ArrayList<Integer> getHealthBoxes() {
return healthBoxes;
}
/**
* Add new listener
*/
public void addNewListener(HealthChangeListener listener) {
healthChangeListeners.add(listener);
}
/**
* Alert all listeners of an update
*/
private void notifyListeners() {
for(HealthChangeListener listener: healthChangeListeners) {
listener.update();
}
}
}
......@@ -68,8 +68,8 @@ public class HealthChanging extends InteractWindow {
//If all values clean, execute damage
if(b >= 0 && l >= 0 && a >= 0) {
health.bashingDamage(-b);
health.lethalDamage(-l);
health.bashingDamage(-(b+l+a));
health.lethalDamage(-(l+a));
health.aggDamage(-a);
updateMessage("Healed "+b+" bashing, "+l+" lethal, and "+a+" agg.");
//If values unclean, present error message
......
package Listeners;
public interface HealthChangeListener {
void update();
}
......@@ -16,13 +16,17 @@ public class HealthBar extends HBox {
private final Text lethalCurrent = new Text();
private final Text aggCurrent = new Text();
private final TextFlow visualHealthBoxes = new TextFlow();
private final Sheet sheet;
public HealthBar() {
public HealthBar(Sheet sheet) {
//Initialise numeric health totals
health = CharacterInterface.getHealth();
healthTypeColumn();
currentHealthColumn();
//Store sheet to class
this.sheet = sheet;
//Add health boxes
VBox visualAndButton = new VBox();
this.getChildren().add(visualAndButton);
......@@ -35,6 +39,12 @@ public class HealthBar extends HBox {
//Set styles
this.getStyleClass().add("healthBar");
//Set health change listener to listen for updates
health.addNewListener(() -> {
updateHealthColumn();
updateVisualHealthBar();
});
}
/**
......@@ -121,6 +131,6 @@ public class HealthBar extends HBox {
* Update interface area when button pressed
*/
private void healthInterface() {
System.out.println("Show the health change window");
sheet.showHealthChanging();
}
}
......@@ -7,7 +7,10 @@ public class Sheet extends BorderPane {
public Sheet() {
this.setTop(new AttributeHeader());
this.setBottom(new HealthBar());
this.setBottom(new HealthBar(this));
}
public void showHealthChanging() {
this.setRight(new HealthChanging());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment