Started working on VoteHandler, reformatted some classes to google style
This commit is contained in:
parent
75027f60b7
commit
7f3ecc0ca9
@ -4,20 +4,22 @@ 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;
|
||||||
|
|
||||||
public class GhostifyHandler {
|
public class GhostifyHandler {
|
||||||
/**
|
/**
|
||||||
* Changes passenger at position x to ghost. Monitors the times the ghostify method is being called. If it's being
|
* Changes passenger at position x to ghost. Monitors the times the ghostify method is 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
|
||||||
* @param p
|
* original ghost.
|
||||||
* Passenger to be ghostified
|
*
|
||||||
*/
|
* @param p Passenger to be ghostified
|
||||||
private static int ghostifyCallCounter = 0;
|
*/
|
||||||
public void ghostify(Passenger p) {
|
private static int ghostifyCallCounter = 0;
|
||||||
p.setGhost();
|
|
||||||
if (ghostifyCallCounter == 0) {
|
public void ghostify(Passenger p) {
|
||||||
GhostPlayer g = new GhostPlayer(p.getPosition(), p.getName(), p.getClientHandler(), true);
|
p.setGhost();
|
||||||
} else {
|
if (ghostifyCallCounter == 0) {
|
||||||
GhostPlayer g = new GhostPlayer(p.getPosition(), p.getName(), p.getClientHandler(), false);
|
GhostPlayer g = new GhostPlayer(p.getPosition(), p.getName(), p.getClientHandler(), true);
|
||||||
}
|
} else {
|
||||||
ghostifyCallCounter++;
|
GhostPlayer g = new GhostPlayer(p.getPosition(), p.getName(), p.getClientHandler(), false);
|
||||||
}
|
}
|
||||||
|
ghostifyCallCounter++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,22 +1,34 @@
|
|||||||
package ch.unibas.dmi.dbis.cs108.gamelogic;
|
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.
|
* Handles the event of voting for humans and ghosts. Differentiates between day and night (human
|
||||||
* - Sends voting request to passengers that need to be concerned
|
* vote / ghost vote) and handles votes accordingly. - Sends voting request to passengers that need
|
||||||
* - collects voting results
|
* to be concerned - collects voting results - calculates who was voted for - decides consequence of
|
||||||
* - calculates who was voted for
|
* vote: - Is it OG ghost: humans win - Is it last human: ghosts win - Is it just a human: message
|
||||||
* - decides consequence of vote:
|
* "x is a human" - Is it a peasant ghost -> kickoff
|
||||||
* - Is Og Ghost: Humans win
|
|
||||||
* - Is last Human: Ghosts win
|
|
||||||
* - Is just a human: Message "x is a human"
|
|
||||||
* - Is 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 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()) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,6 +15,7 @@ public class Passenger {
|
|||||||
protected Boolean isPlayer; //same here
|
protected Boolean isPlayer; //same here
|
||||||
protected Boolean kickedOff; //true if the player has been voted off.
|
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 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.
|
* Sends a protocol message to the respective player.
|
||||||
@ -56,6 +57,10 @@ public class Passenger {
|
|||||||
// changes this passenger's status from human to ghost
|
// changes this passenger's status from human to ghost
|
||||||
isGhost = true;
|
isGhost = true;
|
||||||
}
|
}
|
||||||
|
public void setHasVoted() {
|
||||||
|
// used to signal that this passenger voted during a voting
|
||||||
|
hasVoted = true;
|
||||||
|
}
|
||||||
|
|
||||||
public int getPosition() {
|
public int getPosition() {
|
||||||
return position;
|
return position;
|
||||||
@ -78,6 +83,8 @@ public class Passenger {
|
|||||||
return isPlayer;
|
return isPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getHasVoted() { return hasVoted; };
|
||||||
|
|
||||||
public ClientHandler getClientHandler() {
|
public ClientHandler getClientHandler() {
|
||||||
return clientHandler;
|
return clientHandler;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user