diff --git a/src/controllers/observers/InfectedCityObserver.java b/src/controllers/observers/InfectedCityObserver.java index 255ebb3..bfffa3f 100644 --- a/src/controllers/observers/InfectedCityObserver.java +++ b/src/controllers/observers/InfectedCityObserver.java @@ -5,7 +5,11 @@ import javafx.animation.RotateTransition; import javafx.animation.Timeline; import javafx.scene.Group; +import javafx.scene.layout.VBox; import javafx.scene.shape.MeshView; +import javafx.scene.text.Font; +import javafx.scene.text.FontWeight; +import javafx.scene.text.Text; import javafx.scene.transform.Rotate; import javafx.util.Duration; import models.City; @@ -19,19 +23,28 @@ public class InfectedCityObserver extends Observer { private ArrayList viruses = new ArrayList<>(); private int[] coordinates; private Group sceneItems; + private VBox gameLog; + private boolean prevInfected; - public InfectedCityObserver(City city, int[] coordinates, Group sceneItems){ + public InfectedCityObserver(City city, int[] coordinates, Group sceneItems, VBox gameLog){ this.subject = city; this.subject.attach(this); this.coordinates = coordinates; this.sceneItems = sceneItems; + this.gameLog = gameLog; + this.prevInfected = false; } @Override public void update() { if ( sceneItems != null) { - if (((City) subject).isInfected()) { - if (viruses.isEmpty()) { + if (((City) subject).isInfected() && !prevInfected) { + Text text = new Text(((City) subject).getName() + " is infected!"); + text.setFont(Font.font("Arial", FontWeight.BOLD, 20)); + if ( gameLog.getChildren().size() > 5) { + gameLog.getChildren().subList(0, gameLog.getChildren().size() - 5).clear(); + } + gameLog.getChildren().add(text); int angle = 0; while ( angle <= 360 ){ MeshView virus = MeshImporter.getVirus(); @@ -56,10 +69,18 @@ public void update() { viruses.add(virus); angle += 90; } - } - } else { + prevInfected = true; + } + if ( !((City) subject).isInfected() && prevInfected){ sceneItems.getChildren().removeAll(viruses); viruses.clear(); + Text text = new Text(((City) subject).getName() + " is disinfected from virus!"); + text.setFont(Font.font("Arial", FontWeight.BOLD, 20)); + if ( gameLog.getChildren().size() > 5) { + gameLog.getChildren().subList(0, gameLog.getChildren().size() - 5).clear(); + } + gameLog.getChildren().add(text); + prevInfected = false; } } } diff --git a/src/controllers/scenecontrollers/GameSceneController.java b/src/controllers/scenecontrollers/GameSceneController.java index 3ee2f09..4693817 100644 --- a/src/controllers/scenecontrollers/GameSceneController.java +++ b/src/controllers/scenecontrollers/GameSceneController.java @@ -265,4 +265,8 @@ public static void handlePirateRegionPopup(){ e.printStackTrace(); } } + + public VBox getGameLog() { + return gameLog; + } } diff --git a/src/controllers/scenecontrollers/TableController.java b/src/controllers/scenecontrollers/TableController.java index ae6a029..04ab25e 100644 --- a/src/controllers/scenecontrollers/TableController.java +++ b/src/controllers/scenecontrollers/TableController.java @@ -160,7 +160,7 @@ private void initializeRegions() { } new ColorObserver(regions.get(i), group); new BuildingObserver(regions.get(i), group); - new InfectedCityObserver((City) regions.get(i), coordinates.get(i), sceneItems); + new InfectedCityObserver((City) regions.get(i), coordinates.get(i), sceneItems, gameSceneController.getGameLog()); } else if ( regions.get(i) instanceof ChanceRegion){ region.setMaterial(new PhongMaterial(Color.BLACK)); group.add(getQuestionMark(coordinates.get(i)[0], coordinates.get(i)[1]));