Skip to content

Commit

Permalink
Time stamp is added to game logs
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmethalac committed Dec 20, 2020
1 parent 1dd3535 commit 639a109
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 29 deletions.
3 changes: 3 additions & 0 deletions src/controllers/observers/GameLogObserver.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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) {
Expand Down
60 changes: 31 additions & 29 deletions src/controllers/observers/InfectedCityObserver.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand Down

0 comments on commit 639a109

Please sign in to comment.