Modified GhostifyHandler, added Logger statement
This commit is contained in:
parent
f224324fb5
commit
5cfa6809a2
@ -1,27 +1,27 @@
|
|||||||
package ch.unibas.dmi.dbis.cs108.gamelogic;
|
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.GhostPlayer;
|
||||||
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Passenger;
|
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 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
|
* 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.
|
* 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
|
* @param p Passenger to be ghostified
|
||||||
*/
|
*/
|
||||||
private static int ghostifyCallCounter = -1;
|
|
||||||
|
|
||||||
public GhostPlayer ghost(Passenger p, Game game) {
|
public GhostPlayer ghost(Passenger p, Game game) {
|
||||||
p.setGhost();
|
p.setGhost();
|
||||||
GhostPlayer g;
|
GhostPlayer g;
|
||||||
ghostifyCallCounter++;
|
g = new GhostPlayer(p.getPosition(), p.getName(), p.getClientHandler(), false);
|
||||||
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;
|
game.gameFunctions.passengerTrain[g.getPosition()] = g;
|
||||||
|
LOGGER.info("Passenger at position " + p.getPosition() + "has been ghostified");
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -75,14 +75,14 @@ public class VoteHandler {
|
|||||||
currentMax = votesForPlayer;
|
currentMax = votesForPlayer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGGER.info("Most votes" + currentMax);
|
LOGGER.info("Most votes: " + currentMax + " vote");
|
||||||
|
|
||||||
// ghostify the player with most votes
|
// ghostify the player with most votes
|
||||||
int ghostPosition = 0;
|
int ghostPosition = 0;
|
||||||
for (int i = 0; i < votesForPlayers.length; i++) {
|
for (int i = 0; i < votesForPlayers.length; i++) {
|
||||||
if (votesForPlayers[i] == currentMax) { // if player at position i has most votes
|
if (votesForPlayers[i] == currentMax) { // if player at position i has most votes
|
||||||
ghostPosition = i;
|
ghostPosition = i;
|
||||||
LOGGER.info("Most votes for Passenger" + i);
|
LOGGER.info("Most votes for Passenger " + i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GhostifyHandler gh = new GhostifyHandler();
|
GhostifyHandler gh = new GhostifyHandler();
|
||||||
@ -148,7 +148,7 @@ public class VoteHandler {
|
|||||||
for (int i = 0; i < votesForPlayers.length; i++) {
|
for (int i = 0; i < votesForPlayers.length; i++) {
|
||||||
if (votesForPlayers[i] == currentMax) { // if player has most votes
|
if (votesForPlayers[i] == currentMax) { // if player has most votes
|
||||||
voteIndex = i;
|
voteIndex = i;
|
||||||
LOGGER.info("Player " + voteIndex + "has the most votes");
|
LOGGER.info("Player " + voteIndex + " has the most votes");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!passengers[voteIndex]
|
if (!passengers[voteIndex]
|
||||||
@ -178,11 +178,11 @@ public class VoteHandler {
|
|||||||
// kick this ghost off
|
// kick this ghost off
|
||||||
passengers[voteIndex].setKickedOff(true);
|
passengers[voteIndex].setKickedOff(true);
|
||||||
for (Passenger passenger : passengers) {
|
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) {
|
for (Passenger passenger : passengers) {
|
||||||
passenger.setHasVoted(false);
|
passenger.setHasVoted(false);
|
||||||
}
|
}
|
||||||
@ -221,7 +221,7 @@ public class VoteHandler {
|
|||||||
print(testArray);
|
print(testArray);
|
||||||
|
|
||||||
LOGGER.info("Day");
|
LOGGER.info("Day");
|
||||||
humanVote(testArray);
|
humanVote(testArray, game);
|
||||||
print(testArray);
|
print(testArray);
|
||||||
|
|
||||||
} catch (TrainOverflow e) {
|
} catch (TrainOverflow e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user