[LOG] Add additional logging for convenience

This commit is contained in:
2023-03-28 15:05:14 +01:00
parent afdbf75158
commit f7383f33dc
3 changed files with 28 additions and 0 deletions

View File

@@ -133,6 +133,8 @@ public class Game {
* Handle additional processing after piece has been played - clear lines of blocks
*/
public void afterPiece() {
logger.info("Checking for columns and rows that need clearing");
Set<IntegerProperty> blocksToRemove = new HashSet<>();
int linesToRemove = 0;
@@ -186,12 +188,16 @@ public class Game {
* @param blocks number of blocks cleared
*/
private void score(int lines, int blocks) {
logger.info("Updating score");
var addScore = lines * blocks * 10 * multiplier.get();
score.set(score.get() + addScore);
logger.info("Updating multiplier");
if (lines > 0) multiplier.set(multiplier.get() + 1);
else multiplier.set(1);
logger.info("Setting the level based on the new score");
// set level
level.set((int) Math.floor((double) score.get() / 1000));
}

View File

@@ -3,12 +3,20 @@ package uk.mgrove.ac.soton.comp1206.ui;
import javafx.beans.property.IntegerProperty;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import uk.mgrove.ac.soton.comp1206.game.Game;
/**
* Stats menu class to show basic stats about game status
*/
public class StatsMenu extends VBox {
/**
* Logger
*/
private static final Logger logger = LogManager.getLogger(Game.class);
/**
* Player's current score
*/
@@ -34,6 +42,8 @@ public class StatsMenu extends VBox {
* @param multiplier multiplier property
*/
public StatsMenu(IntegerProperty score, IntegerProperty level, IntegerProperty lives, IntegerProperty multiplier) {
logger.info("Initialising new stats menu with score {}, level {}, lives {}, and multiplier {}", score.get(), level.get(), lives.get(), multiplier.get());
this.score.textProperty().bind(score.asString());
this.level.textProperty().bind(level.asString());
this.lives.textProperty().bind(lives.asString());

View File

@@ -2,9 +2,17 @@ package uk.mgrove.ac.soton.comp1206.util;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import uk.mgrove.ac.soton.comp1206.game.Game;
public class Multimedia {
/**
* Logger
*/
private static final Logger logger = LogManager.getLogger(Game.class);
/**
* Media player for game music
*/
@@ -19,6 +27,8 @@ public class Multimedia {
* @param filePath file path of audio file
*/
public static void playAudio(String filePath) {
logger.info("Playing sound effect from file: {}", filePath);
if (audioPlayer != null) audioPlayer.stop();
var media = new Media(Multimedia.class.getResource("/" + filePath).toExternalForm());
audioPlayer = new MediaPlayer(media);
@@ -30,6 +40,8 @@ public class Multimedia {
* @param filePath file path of audio file
*/
public static void playMusic(String filePath) {
logger.info("Playing music from file: {}", filePath);
if (musicPlayer != null) musicPlayer.stop();
var media = new Media(Multimedia.class.getResource("/" + filePath).toExternalForm());
musicPlayer = new MediaPlayer(media);