From 5cfa6809a2806ab376fcc15bbf39785cf3eb7e44 Mon Sep 17 00:00:00 2001 From: Alexander Sazonov Date: Fri, 8 Apr 2022 11:27:52 +0200 Subject: [PATCH] Modified GhostifyHandler, added Logger statement --- .../dmi/dbis/cs108/gamelogic/GhostifyHandler.java | 14 +++++++------- .../dmi/dbis/cs108/gamelogic/VoteHandler.java | 12 ++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/GhostifyHandler.java b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/GhostifyHandler.java index 553ad19..f95a887 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/GhostifyHandler.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/GhostifyHandler.java @@ -1,27 +1,27 @@ package ch.unibas.dmi.dbis.cs108.gamelogic; +import ch.unibas.dmi.dbis.cs108.BudaLogConfig; import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.GhostPlayer; import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Passenger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class GhostifyHandler { + public static final Logger LOGGER = LogManager.getLogger(); + public static final BudaLogConfig l = new BudaLogConfig(LOGGER); /** * Changes passenger at position x to ghost and returns this ghost. Monitors the times the ghost method is being * called. If it's being called for the first time, the ghostified player is being set as the original ghost. * * @param p Passenger to be ghostified */ - private static int ghostifyCallCounter = -1; public GhostPlayer ghost(Passenger p, Game game) { p.setGhost(); GhostPlayer g; - ghostifyCallCounter++; - if (ghostifyCallCounter == 0) { - g = new GhostPlayer(p.getPosition(), p.getName(), p.getClientHandler(), true); - } else { - g = new GhostPlayer(p.getPosition(), p.getName(), p.getClientHandler(), false); - } + g = new GhostPlayer(p.getPosition(), p.getName(), p.getClientHandler(), false); game.gameFunctions.passengerTrain[g.getPosition()] = g; + LOGGER.info("Passenger at position " + p.getPosition() + "has been ghostified"); return g; } } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/VoteHandler.java b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/VoteHandler.java index a0befff..2264ba7 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/VoteHandler.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/VoteHandler.java @@ -75,14 +75,14 @@ public class VoteHandler { currentMax = votesForPlayer; } } - LOGGER.info("Most votes" + currentMax); + LOGGER.info("Most votes: " + currentMax + " vote"); // ghostify the player with most votes int ghostPosition = 0; for (int i = 0; i < votesForPlayers.length; i++) { if (votesForPlayers[i] == currentMax) { // if player at position i has most votes ghostPosition = i; - LOGGER.info("Most votes for Passenger" + i); + LOGGER.info("Most votes for Passenger " + i); } } GhostifyHandler gh = new GhostifyHandler(); @@ -148,7 +148,7 @@ public class VoteHandler { for (int i = 0; i < votesForPlayers.length; i++) { if (votesForPlayers[i] == currentMax) { // if player has most votes voteIndex = i; - LOGGER.info("Player " + voteIndex + "has the most votes"); + LOGGER.info("Player " + voteIndex + " has the most votes"); } } if (!passengers[voteIndex] @@ -178,11 +178,11 @@ public class VoteHandler { // kick this ghost off passengers[voteIndex].setKickedOff(true); for (Passenger passenger : passengers) { - passenger.send("Player " + voteIndex + "has been kicked off!"); + passenger.send("Player " + voteIndex + " has been kicked off!"); } } } - // set hasVoted to false for all passengers for future votings + // set hasVoted to false for all passengers for future voting for (Passenger passenger : passengers) { passenger.setHasVoted(false); } @@ -221,7 +221,7 @@ public class VoteHandler { print(testArray); LOGGER.info("Day"); - humanVote(testArray); + humanVote(testArray, game); print(testArray); } catch (TrainOverflow e) {