Started working on VoteHandler, reformatted some classes to google style

This commit is contained in:
Alexander Sazonov 2022-04-03 00:55:24 +02:00
parent 75027f60b7
commit 7f3ecc0ca9
3 changed files with 50 additions and 29 deletions

View File

@ -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++;
}
}

View File

@ -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)
* <p>(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
* <p>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()) {
}
}
}
}

View File

@ -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;
}