Outsourced all messages sent by votehandler and noisehandler to ClientGameInfoHandler
This commit is contained in:
parent
ac80a88b98
commit
fcd93c4d58
@ -10,6 +10,24 @@ import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Passenger;
|
|||||||
|
|
||||||
public class ClientGameInfoHandler {
|
public class ClientGameInfoHandler {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All messages that are used in VoteHandler
|
||||||
|
*/
|
||||||
|
//relevant:
|
||||||
|
public static final String ghostVoteRequest = "Vote on who to ghostify!";
|
||||||
|
public static final String humanVoteRequest = "Vote for a ghost to kick off!";
|
||||||
|
public static final String noiseNotification = "noise";
|
||||||
|
public static final String gameOverHumansWin = "Game over: humans win!";
|
||||||
|
public static final String gameOverGhostsWin = "Game over: ghosts win!";
|
||||||
|
|
||||||
|
//just messages
|
||||||
|
public static final String itsNightTime = "Please wait, ghosts are active";
|
||||||
|
public static final String youGotGhostyfied = "You are now a ghost!";
|
||||||
|
public static final String itsDayTime = "Please wait, humans are active";
|
||||||
|
public static final String humansVotedFor = "Humans voted for:";
|
||||||
|
public static final String isAHuman = "but they're a human!";
|
||||||
|
public static final String gotKickedOff = "is a Ghost and got kicked off";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sends a msg "" to Server stating who voted for who, this being the Client that votes
|
* sends a msg "" to Server stating who voted for who, this being the Client that votes
|
||||||
* @param position the position of the passenger that is voted for
|
* @param position the position of the passenger that is voted for
|
||||||
|
|||||||
@ -27,10 +27,10 @@ public class ServerGameInfoHandler {
|
|||||||
*/
|
*/
|
||||||
public static String format(String msg, Passenger p, Game game) {
|
public static String format(String msg, Passenger p, Game game) {
|
||||||
switch (msg) {
|
switch (msg) {
|
||||||
case "Vote on who to ghostify!":
|
case ClientGameInfoHandler.ghostVoteRequest:
|
||||||
msg = Protocol.serverRequestsGhostVote + "$" + p.getPosition() +"$" + game.gameState.toString();
|
msg = Protocol.serverRequestsGhostVote + "$" + p.getPosition() +"$" + game.gameState.toString();
|
||||||
break;
|
break;
|
||||||
case "Vote for a ghost to kick off!":
|
case ClientGameInfoHandler.humanVoteRequest:
|
||||||
msg = Protocol.serverRequestsHumanVote + "$" + p.getPosition() +"$"+ game.gameState.humanToString();
|
msg = Protocol.serverRequestsHumanVote + "$" + p.getPosition() +"$"+ game.gameState.humanToString();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -42,10 +42,11 @@ public class ServerGameInfoHandler {
|
|||||||
|
|
||||||
public static void ghostNpcParser(GhostNPC npc, String msg, Game game) {
|
public static void ghostNpcParser(GhostNPC npc, String msg, Game game) {
|
||||||
switch (msg) {
|
switch (msg) {
|
||||||
case "noise":
|
case ClientGameInfoHandler.noiseNotification:
|
||||||
|
//TODO(Seraina & Alex): noise handling
|
||||||
npc.noise();
|
npc.noise();
|
||||||
break;
|
break;
|
||||||
case "Vote on who to ghostify!":
|
case ClientGameInfoHandler.ghostVoteRequest:
|
||||||
npc.vote(game);
|
npc.vote(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,10 +55,10 @@ public class ServerGameInfoHandler {
|
|||||||
|
|
||||||
public static void humanNpcParser(HumanNPC npc, String msg, Game game) {
|
public static void humanNpcParser(HumanNPC npc, String msg, Game game) {
|
||||||
switch (msg) {
|
switch (msg) {
|
||||||
case "noise":
|
case ClientGameInfoHandler.noiseNotification:
|
||||||
npc.noise();
|
npc.noise();
|
||||||
break;
|
break;
|
||||||
case "Vote for a ghost to kick off!":
|
case ClientGameInfoHandler.humanVoteRequest:
|
||||||
npc.vote();
|
npc.vote();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -56,10 +56,10 @@ public class VoteHandler {
|
|||||||
for (Passenger passenger : passengers) {
|
for (Passenger passenger : passengers) {
|
||||||
if (passenger.getIsGhost()) {
|
if (passenger.getIsGhost()) {
|
||||||
|
|
||||||
passenger.send("Vote on who to ghostify!", game);
|
passenger.send(ClientGameInfoHandler.ghostVoteRequest, game);
|
||||||
} else {
|
} else {
|
||||||
passenger.send(
|
passenger.send(
|
||||||
"Please wait, ghosts are active", game);
|
ClientGameInfoHandler.itsNightTime, game);
|
||||||
// this time, except chat is ignored
|
// this time, except chat is ignored
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -111,7 +111,7 @@ public class VoteHandler {
|
|||||||
Ghost g = gh.ghost(passengers[ghostPosition], game);
|
Ghost g = gh.ghost(passengers[ghostPosition], game);
|
||||||
passengers[ghostPosition] = g;
|
passengers[ghostPosition] = g;
|
||||||
passengers[ghostPosition].send(
|
passengers[ghostPosition].send(
|
||||||
"You are now a ghost!", game); // TODO: ServerGameInfoHandler might deal with this one
|
ClientGameInfoHandler.youGotGhostyfied, game); // TODO: ServerGameInfoHandler might deal with this one
|
||||||
|
|
||||||
LOGGER.info(game.getGameState().toString());
|
LOGGER.info(game.getGameState().toString());
|
||||||
// set hasVoted to false for all passengers for future votings
|
// set hasVoted to false for all passengers for future votings
|
||||||
@ -140,9 +140,9 @@ public class VoteHandler {
|
|||||||
// TODO: Messages in for-loop should probably be handled by ServerGameInfoHandler
|
// TODO: Messages in for-loop should probably be handled by ServerGameInfoHandler
|
||||||
for (Passenger passenger : passengers) {
|
for (Passenger passenger : passengers) {
|
||||||
if (passenger.getIsGhost()) {
|
if (passenger.getIsGhost()) {
|
||||||
passenger.send("Please wait, humans are active", game);
|
passenger.send(ClientGameInfoHandler.itsDayTime, game);
|
||||||
} else {
|
} else {
|
||||||
passenger.send("Vote for a ghost to kick off!", game);
|
passenger.send(ClientGameInfoHandler.humanVoteRequest , game);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,13 +185,13 @@ public class VoteHandler {
|
|||||||
.getIsGhost()) { // if player with most votes is human, notify everyone about it
|
.getIsGhost()) { // if player with most votes is human, notify everyone about it
|
||||||
for (Passenger passenger : passengers) {
|
for (Passenger passenger : passengers) {
|
||||||
passenger.send(
|
passenger.send(
|
||||||
"You voted for a human!", game); // TODO: ServerGameInfoHandler might be better to use here
|
ClientGameInfoHandler.humansVotedFor + voteIndex + ClientGameInfoHandler.isAHuman, game); // TODO: ServerGameInfoHandler might be better to use here
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (passengers[voteIndex].getIsGhost()) { // if player is a ghost
|
if (passengers[voteIndex].getIsGhost()) { // if player is a ghost
|
||||||
if (passengers[voteIndex].getIsOG()) { // if ghost is OG --> end game, humans win
|
if (passengers[voteIndex].getIsOG()) { // if ghost is OG --> end game, humans win
|
||||||
System.out.println("Game over: humans win!"); // TODO: correctly handle end of game
|
System.out.println(ClientGameInfoHandler.gameOverHumansWin); // TODO: correctly handle end of game
|
||||||
return "Game over: humans win!";
|
return ClientGameInfoHandler.gameOverHumansWin;
|
||||||
} else {
|
} else {
|
||||||
/* Special case: if ghost is not OG and if only one human is left (--> last human didn't vote for OG ghost),
|
/* Special case: if ghost is not OG and if only one human is left (--> last human didn't vote for OG ghost),
|
||||||
ghosts win.
|
ghosts win.
|
||||||
@ -203,14 +203,14 @@ public class VoteHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (humans == 1) {
|
if (humans == 1) {
|
||||||
System.out.println("Game over: ghosts win!");
|
System.out.println(ClientGameInfoHandler.gameOverGhostsWin);
|
||||||
return "Game over: ghosts win!";
|
return ClientGameInfoHandler.gameOverGhostsWin;
|
||||||
}
|
}
|
||||||
// Usual case: there is more than one human left and a normal ghost has been voted for -->
|
// Usual case: there is more than one human left and a normal ghost has been voted for -->
|
||||||
// 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!", game);
|
passenger.send("Player " + voteIndex + ClientGameInfoHandler.gotKickedOff, game);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -248,38 +248,4 @@ public class VoteHandler {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*public static void main(String[] args) {
|
|
||||||
try {
|
|
||||||
Game game = new Game(6,1, 6);
|
|
||||||
VoteHandler voteHandler = new VoteHandler();
|
|
||||||
|
|
||||||
Passenger[] testArray = game.gameState.getPassengerTrain();
|
|
||||||
Passenger ghost = new Ghost();
|
|
||||||
testArray[3] = ghost;
|
|
||||||
testArray[3].setGhost();
|
|
||||||
testArray[3].setIsOg();
|
|
||||||
testArray[3].setPosition(3);
|
|
||||||
print(testArray);
|
|
||||||
LOGGER.info("NIGHT");
|
|
||||||
voteHandler.ghostVote(testArray,game);
|
|
||||||
print(testArray);
|
|
||||||
|
|
||||||
LOGGER.info("Day");
|
|
||||||
voteHandler.humanVote(testArray, game);
|
|
||||||
print(testArray);
|
|
||||||
|
|
||||||
LOGGER.info("NIGHT");
|
|
||||||
voteHandler.ghostVote(testArray,game);
|
|
||||||
print(testArray);
|
|
||||||
|
|
||||||
LOGGER.info("Day");
|
|
||||||
voteHandler.humanVote(testArray, game);
|
|
||||||
print(testArray);
|
|
||||||
} catch (TrainOverflow e) {
|
|
||||||
LOGGER.warn(e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user