Modified GhostifyHandler, added Logger statement

This commit is contained in:
Alexander Sazonov 2022-04-08 11:27:52 +02:00
parent f224324fb5
commit 5cfa6809a2
2 changed files with 13 additions and 13 deletions

View File

@ -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);
}
game.gameFunctions.passengerTrain[g.getPosition()] = g;
LOGGER.info("Passenger at position " + p.getPosition() + "has been ghostified");
return g;
}
}

View File

@ -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) {