Added getVoteFromClient method to superclass Passenger so when NPC vote, nothing happens when this method is called

This commit is contained in:
Seraina 2022-04-09 08:45:57 +02:00
parent 09024dbfad
commit 96b0fa70ef
3 changed files with 40 additions and 0 deletions

View File

@ -38,5 +38,24 @@ public class GhostPlayer extends Ghost {
String formattedMsg = ServerGameInfoHandler.format(msg, game); String formattedMsg = ServerGameInfoHandler.format(msg, game);
clientHandler.sendMsgToClient(formattedMsg); clientHandler.sendMsgToClient(formattedMsg);
} }
/**
* Gets the voting information vote and hasVoted from clientHandler and this values to those values.
* Sets clientHandler fields to default: vote = Integer.MAX_VALUE , hasVoted = false
*/
@Override
public void getVoteFromClientHandler() {
vote = clientHandler.getVote();
hasVoted = clientHandler.getHasVoted();
clientHandler.setVote(Integer.MAX_VALUE);
clientHandler.setHasVoted(false);
/*
* if vote wasn't valid, make sure, the passenger field hasVoted == false, probably redundant but better be safe than sorry
*/
if(vote == Integer.MAX_VALUE) {
hasVoted = false;
}
}
} }

View File

@ -35,4 +35,22 @@ public class HumanPlayer extends Human {
String formattedMsg = ServerGameInfoHandler.format(msg, game); String formattedMsg = ServerGameInfoHandler.format(msg, game);
clientHandler.sendMsgToClient(formattedMsg); clientHandler.sendMsgToClient(formattedMsg);
} }
/**
* Gets the voting information vote and hasVoted from clientHandler and this values to those values.
* Sets clientHandler fields to default: vote = Integer.MAX_VALUE , hasVoted = false
*/
@Override
public void getVoteFromClientHandler() {
vote = clientHandler.getVote();
hasVoted = clientHandler.getHasVoted();
clientHandler.setVote(Integer.MAX_VALUE);
clientHandler.setHasVoted(false);
/*
* if vote wasn't valid, make sure, the passenger field hasVoted == false, probably redundant but better be safe than sorry
*/
if(vote == Integer.MAX_VALUE) {
hasVoted = false;
}
}
} }

View File

@ -109,4 +109,7 @@ public class Passenger {
return clientHandler; return clientHandler;
} }
public void getVoteFromClientHandler() {
}
} }