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 a971eef..e591a1c 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 @@ -4,20 +4,22 @@ import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.GhostPlayer; import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Passenger; public class GhostifyHandler { - /** - * Changes passenger at position x to ghost. Monitors the times the ghostify 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 = 0; - public void ghostify(Passenger p) { - p.setGhost(); - if (ghostifyCallCounter == 0) { - GhostPlayer g = new GhostPlayer(p.getPosition(), p.getName(), p.getClientHandler(), true); - } else { - GhostPlayer g = new GhostPlayer(p.getPosition(), p.getName(), p.getClientHandler(), false); - } - ghostifyCallCounter++; + /** + * Changes passenger at position x to ghost. Monitors the times the ghostify 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 = 0; + + public void ghostify(Passenger p) { + p.setGhost(); + if (ghostifyCallCounter == 0) { + GhostPlayer g = new GhostPlayer(p.getPosition(), p.getName(), p.getClientHandler(), true); + } else { + GhostPlayer g = new GhostPlayer(p.getPosition(), p.getName(), p.getClientHandler(), false); } + ghostifyCallCounter++; + } } 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 ba18e2a..3afd5f9 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 @@ -1,22 +1,34 @@ package ch.unibas.dmi.dbis.cs108.gamelogic; +import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Passenger; +import ch.unibas.dmi.dbis.cs108.multiplayer.server.ClientHandler; + /** - * Handles the Event of Voting for Humans and Ghosts. Differentiates between day and night (human Ghost) and handles votes accordingly. - * - Sends voting request to passengers that need to be concerned - * - collects voting results - * - calculates who was voted for - * - decides consequence of vote: - * - Is Og Ghost: Humans win - * - Is last Human: Ghosts win - * - Is just a human: Message "x is a human" - * - Is a peasant Ghost -> kickoff + * Handles the event of voting for humans and ghosts. Differentiates between day and night (human + * vote / ghost vote) and handles votes accordingly. - Sends voting request to passengers that need + * to be concerned - collects voting results - calculates who was voted for - decides consequence of + * vote: - Is it OG ghost: humans win - Is it last human: ghosts win - Is it just a human: message + * "x is a human" - Is it a peasant ghost -> kickoff * - * (All messages going to Clients are handled via ServerGameInfoHandler) + *

(All messages going to Clients are handled via ServerGameInfoHandler) * - * TODO: Think about if the timer needs to be implemented here or in the Game class + *

TODO: Think about if the timer needs to be implemented here or in the Game class */ - public class VoteHandler { - - + public static void ghostVote(Passenger[] passengers) { + // Walk through entire train, ask ghosts to ghostify and humans to wait + // TODO: Messages in for-loop should be handled by ServerGameInfoHandler + for (Passenger passenger : passengers) { + if (passenger.getIsGhost()) { + passenger.send("Vote on who to ghostify!"); + } else { + passenger.send("Please wait, ghosts are active"); + } + } + for (Passenger passenger : passengers) { + // TODO (Alex): Count received votes and deal with results + if (passenger.getHasVoted()) { + } + } + } } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/klassenstruktur/Passenger.java b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/klassenstruktur/Passenger.java index b647dad..0d49bd8 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/klassenstruktur/Passenger.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/gamelogic/klassenstruktur/Passenger.java @@ -15,6 +15,7 @@ public class Passenger { protected Boolean isPlayer; //same here protected Boolean kickedOff; //true if the player has been voted off. protected ClientHandler clientHandler; //the socket for the client associated with this Passenger, for NPCs, this can be null. + protected boolean hasVoted; //true if the player gave his vote during voting time /** * Sends a protocol message to the respective player. @@ -56,6 +57,10 @@ public class Passenger { // changes this passenger's status from human to ghost isGhost = true; } + public void setHasVoted() { + // used to signal that this passenger voted during a voting + hasVoted = true; + } public int getPosition() { return position; @@ -78,6 +83,8 @@ public class Passenger { return isPlayer; } + public boolean getHasVoted() { return hasVoted; }; + public ClientHandler getClientHandler() { return clientHandler; }