diff --git a/src/controllers/observers/GameLogObserver.java b/src/controllers/observers/GameLogObserver.java index 9a82041..2e86553 100644 --- a/src/controllers/observers/GameLogObserver.java +++ b/src/controllers/observers/GameLogObserver.java @@ -5,6 +5,8 @@ import javafx.scene.text.FontWeight; import javafx.scene.text.Text; import models.Player; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; public class GameLogObserver extends Observer { @@ -56,6 +58,7 @@ public void update(String changeType, double amount){ log = name + " sold " + changeType.replaceAll("removeCity", ""); } } + log += " [" + LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_TIME).substring(0,8) + "]"; Text text = new Text(log); text.setFont(Font.font("Arial", FontWeight.BOLD, 20)); if ( gameLog.getChildren().size() > 5) { diff --git a/src/controllers/observers/InfectedCityObserver.java b/src/controllers/observers/InfectedCityObserver.java index bfffa3f..2f5ecfa 100644 --- a/src/controllers/observers/InfectedCityObserver.java +++ b/src/controllers/observers/InfectedCityObserver.java @@ -15,7 +15,8 @@ import models.City; import storage.filemanager.MeshImporter; -import java.sql.Time; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; public class InfectedCityObserver extends Observer { @@ -39,37 +40,38 @@ public InfectedCityObserver(City city, int[] coordinates, Group sceneItems, VBox public void update() { if ( sceneItems != null) { 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(); - double yOffset = 35 * Math.cos(angle * Math.PI / 180); - double xOffset = 35 * Math.sin(angle * Math.PI / 180); - - virus.setTranslateX(coordinates[0] + xOffset); - virus.setTranslateY(coordinates[1] + yOffset); + String log = ((City) subject).getName() + " is infected!"; + log += " [" + LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_TIME).substring(0,8) + "]"; + Text text = new Text(log); + 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(); + double yOffset = 35 * Math.cos(angle * Math.PI / 180); + double xOffset = 35 * Math.sin(angle * Math.PI / 180); + virus.setTranslateX(coordinates[0] + xOffset); + virus.setTranslateY(coordinates[1] + yOffset); - Rotate rotate = new Rotate(); - rotate.setPivotX(-xOffset); - rotate.setPivotY(-yOffset); + Rotate rotate = new Rotate(); + rotate.setPivotX(-xOffset); + rotate.setPivotY(-yOffset); - virus.getTransforms().add(rotate); - Timeline timeline = new Timeline( - new KeyFrame(Duration.ZERO, new KeyValue(rotate.angleProperty(), 0)), - new KeyFrame(Duration.seconds(3), new KeyValue(rotate.angleProperty(), 360))); - timeline.setCycleCount(Timeline.INDEFINITE); - timeline.play(); + virus.getTransforms().add(rotate); + Timeline timeline = new Timeline( + new KeyFrame(Duration.ZERO, new KeyValue(rotate.angleProperty(), 0)), + new KeyFrame(Duration.seconds(3), new KeyValue(rotate.angleProperty(), 360))); + timeline.setCycleCount(Timeline.INDEFINITE); + timeline.play(); - sceneItems.getChildren().add(virus); - viruses.add(virus); - angle += 90; - } - prevInfected = true; + sceneItems.getChildren().add(virus); + viruses.add(virus); + angle += 90; + } + prevInfected = true; } if ( !((City) subject).isInfected() && prevInfected){ sceneItems.getChildren().removeAll(viruses);