Fixed some wonky bugs, and added minimum vote time of 5 seconds to calm the game down a litte
This commit is contained in:
parent
17fc986c50
commit
a8fa462949
@ -36,7 +36,11 @@ public class ServerGameInfoHandler {
|
|||||||
msg = Protocol.serverRequestsHumanVote + "$" + passenger.getPosition() + "$";
|
msg = Protocol.serverRequestsHumanVote + "$" + passenger.getPosition() + "$";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
msg = Protocol.printToClientConsole + "$" + msg;
|
if(!msg.contains("$")) {
|
||||||
|
msg = Protocol.printToClientConsole + "$" + msg;
|
||||||
|
} else {
|
||||||
|
msg = msg;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
LOGGER.debug(msg);
|
LOGGER.debug(msg);
|
||||||
return msg;
|
return msg;
|
||||||
@ -64,7 +68,11 @@ public class ServerGameInfoHandler {
|
|||||||
msg = Protocol.printToGUI + "$" + GuiParameters.updateGameState + game.getGameState().toString();
|
msg = Protocol.printToGUI + "$" + GuiParameters.updateGameState + game.getGameState().toString();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
msg = Protocol.printToClientConsole + "$" + msg;
|
if(!msg.contains("$")) {
|
||||||
|
msg = Protocol.printToClientConsole + "$" + msg;
|
||||||
|
} else {
|
||||||
|
msg = msg;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
LOGGER.debug(msg);
|
LOGGER.debug(msg);
|
||||||
return msg;
|
return msg;
|
||||||
@ -112,7 +120,6 @@ public class ServerGameInfoHandler {
|
|||||||
case ClientGameInfoHandler.noiseNotification + 5 + " time(s)":
|
case ClientGameInfoHandler.noiseNotification + 5 + " time(s)":
|
||||||
String outMsg = npc.getName() + ": " + noiseRandomizer();
|
String outMsg = npc.getName() + ": " + noiseRandomizer();
|
||||||
//TODO: add likelyhood
|
//TODO: add likelyhood
|
||||||
Timer.ghostAfterVoteTimer();
|
|
||||||
game.getLobby().getAdmin().broadcastNpcChatMessageToLobby(outMsg);
|
game.getLobby().getAdmin().broadcastNpcChatMessageToLobby(outMsg);
|
||||||
game.getLobby().getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + "$" + GuiParameters.noiseHeardAtPosition
|
game.getLobby().getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + "$" + GuiParameters.noiseHeardAtPosition
|
||||||
+ "$" + npc.getPosition());
|
+ "$" + npc.getPosition());
|
||||||
@ -137,7 +144,6 @@ public class ServerGameInfoHandler {
|
|||||||
case ClientGameInfoHandler.noiseNotification + 4 + " time(s)":
|
case ClientGameInfoHandler.noiseNotification + 4 + " time(s)":
|
||||||
case ClientGameInfoHandler.noiseNotification + 5 + " time(s)":
|
case ClientGameInfoHandler.noiseNotification + 5 + " time(s)":
|
||||||
String outMsg = npc.getName() + ": " + noiseRandomizer();
|
String outMsg = npc.getName() + ": " + noiseRandomizer();
|
||||||
Timer.ghostAfterVoteTimer();
|
|
||||||
game.getLobby().getAdmin().broadcastNpcChatMessageToLobby(outMsg);
|
game.getLobby().getAdmin().broadcastNpcChatMessageToLobby(outMsg);
|
||||||
game.getLobby().getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + "$" + GuiParameters.noiseHeardAtPosition
|
game.getLobby().getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + "$" + GuiParameters.noiseHeardAtPosition
|
||||||
+ "$" + npc.getPosition());
|
+ "$" + npc.getPosition());
|
||||||
|
|||||||
@ -39,6 +39,11 @@ public class Timer {
|
|||||||
*/
|
*/
|
||||||
public static final int interval = 1;
|
public static final int interval = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The minimal vote time, in seconds
|
||||||
|
*/
|
||||||
|
public static final int minVoteTime = 5;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The timer for the ghost vote. Checks every {@code interval} seconds if every ghost has already voted.
|
* The timer for the ghost vote. Checks every {@code interval} seconds if every ghost has already voted.
|
||||||
* If all have voted or if the {@code ghostVoteTime} value is reached, the timer ends
|
* If all have voted or if the {@code ghostVoteTime} value is reached, the timer ends
|
||||||
@ -47,7 +52,7 @@ public class Timer {
|
|||||||
public static void ghostVoteTimer(Game game) {
|
public static void ghostVoteTimer(Game game) {
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
while(counter < ghostVoteTime) {
|
while(counter < ghostVoteTime) {
|
||||||
if(haveAllGhostsVoted(game)) { //if all ghost have voted
|
if(haveAllGhostsVoted(game) && counter > minVoteTime) { //if all ghost have voted
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -62,7 +67,7 @@ public class Timer {
|
|||||||
public static void humanVoteTimer(Game game) {
|
public static void humanVoteTimer(Game game) {
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
while (counter < humanVoteTime) {
|
while (counter < humanVoteTime) {
|
||||||
if (haveAllHumansVoted(game)) return;
|
if (haveAllHumansVoted(game) && counter > minVoteTime) return;
|
||||||
try {
|
try {
|
||||||
Thread.sleep(interval*1000);
|
Thread.sleep(interval*1000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
|||||||
@ -68,7 +68,6 @@ public class VoteHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOGGER.info("Most votes for: " + newGhostPosition);
|
LOGGER.info("Most votes for: " + newGhostPosition);
|
||||||
Timer.ghostAfterVoteTimer();
|
|
||||||
for(Passenger passenger : passengers) {
|
for(Passenger passenger : passengers) {
|
||||||
if(passenger.getIsGhost() || passenger.getIsSpectator()) {
|
if(passenger.getIsGhost() || passenger.getIsSpectator()) {
|
||||||
passenger.send(passengers[newGhostPosition].getName() + ClientGameInfoHandler.gotGhostyfied, game);
|
passenger.send(passengers[newGhostPosition].getName() + ClientGameInfoHandler.gotGhostyfied, game);
|
||||||
@ -87,7 +86,6 @@ public class VoteHandler {
|
|||||||
walk by is being updated. Finally, each passenger receives information about how often he heard something during
|
walk by is being updated. Finally, each passenger receives information about how often he heard something during
|
||||||
this night. The player who's just been ghostified is ignored since he didn't participate in this night's
|
this night. The player who's just been ghostified is ignored since he didn't participate in this night's
|
||||||
ghostification. */
|
ghostification. */
|
||||||
Timer.ghostAfterVoteTimer();
|
|
||||||
int[] noiseAmount = new int[6];
|
int[] noiseAmount = new int[6];
|
||||||
for (int i = 0; i < passengers.length; i++) {
|
for (int i = 0; i < passengers.length; i++) {
|
||||||
if (passengers[i].getIsGhost() && i != newGhostPosition) {
|
if (passengers[i].getIsGhost() && i != newGhostPosition) {
|
||||||
|
|||||||
@ -346,6 +346,7 @@ public class Client {
|
|||||||
break;
|
break;
|
||||||
case GuiParameters.day: //ClientGameInfoHandler
|
case GuiParameters.day: //ClientGameInfoHandler
|
||||||
gameStateModel.setDayClone(true);
|
gameStateModel.setDayClone(true);
|
||||||
|
chatApp.getGameController().setNoiseButtonVisible();
|
||||||
break;
|
break;
|
||||||
case GuiParameters.updateGameState:
|
case GuiParameters.updateGameState:
|
||||||
gameStateModel.setGSFromString(data);
|
gameStateModel.setGSFromString(data);
|
||||||
|
|||||||
@ -39,6 +39,7 @@ public class JClientProtocolParser {
|
|||||||
c.clientPinger.setGotPingBack(true);
|
c.clientPinger.setGotPingBack(true);
|
||||||
break;
|
break;
|
||||||
case Protocol.printToClientConsole:
|
case Protocol.printToClientConsole:
|
||||||
|
LOGGER.debug(msg);
|
||||||
System.out.println(msg.substring(6));
|
System.out.println(msg.substring(6));
|
||||||
if (!msg.substring(6).equals("Your vote was invalid")) {
|
if (!msg.substring(6).equals("Your vote was invalid")) {
|
||||||
c.notificationTextDisplay(msg.substring(6));
|
c.notificationTextDisplay(msg.substring(6));
|
||||||
@ -83,8 +84,9 @@ public class JClientProtocolParser {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.warn(msg.substring(6));
|
LOGGER.warn(msg.substring(6));
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
System.out.println("Received unknown command");
|
System.out.println("Received unknown command: " + msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -117,7 +117,6 @@ public class GameStateModel {
|
|||||||
j = right.indexOf(':');
|
j = right.indexOf(':');
|
||||||
roles[i] = right.substring(0, j);
|
roles[i] = right.substring(0, j);
|
||||||
kickedOff[i] = Boolean.parseBoolean(right.substring(j + 1));
|
kickedOff[i] = Boolean.parseBoolean(right.substring(j + 1));
|
||||||
LOGGER.info(kickedOff[i]);
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
setPassengerTrainClone(names, roles);
|
setPassengerTrainClone(names, roles);
|
||||||
|
|||||||
@ -268,7 +268,7 @@ public class GameController implements Initializable{
|
|||||||
if(kickedOff[1]) {
|
if(kickedOff[1]) {
|
||||||
role1 = new Text("\nkicked off");
|
role1 = new Text("\nkicked off");
|
||||||
} else {
|
} else {
|
||||||
role1 = new Text("\n" + roles[0]);
|
role1 = new Text("\n" + roles[1]);
|
||||||
}
|
}
|
||||||
role1.setStyle("-fx-font: 25 arial;");
|
role1.setStyle("-fx-font: 25 arial;");
|
||||||
role1.setFill(Color.WHITE);
|
role1.setFill(Color.WHITE);
|
||||||
@ -276,7 +276,7 @@ public class GameController implements Initializable{
|
|||||||
if(kickedOff[2]) {
|
if(kickedOff[2]) {
|
||||||
role2 = new Text("\nkicked off");
|
role2 = new Text("\nkicked off");
|
||||||
} else {
|
} else {
|
||||||
role2 = new Text("\n" + roles[0]);
|
role2 = new Text("\n" + roles[2]);
|
||||||
}
|
}
|
||||||
role2.setStyle("-fx-font: 25 arial;");
|
role2.setStyle("-fx-font: 25 arial;");
|
||||||
role2.setFill(Color.WHITE);
|
role2.setFill(Color.WHITE);
|
||||||
@ -284,7 +284,7 @@ public class GameController implements Initializable{
|
|||||||
if(kickedOff[3]) {
|
if(kickedOff[3]) {
|
||||||
role3 = new Text("\nkicked off");
|
role3 = new Text("\nkicked off");
|
||||||
} else {
|
} else {
|
||||||
role3 = new Text("\n" + roles[0]);
|
role3 = new Text("\n" + roles[3]);
|
||||||
}
|
}
|
||||||
role3.setStyle("-fx-font: 25 arial;");
|
role3.setStyle("-fx-font: 25 arial;");
|
||||||
role3.setFill(Color.WHITE);
|
role3.setFill(Color.WHITE);
|
||||||
@ -292,7 +292,7 @@ public class GameController implements Initializable{
|
|||||||
if(kickedOff[4]) {
|
if(kickedOff[4]) {
|
||||||
role4 = new Text("\nkicked off");
|
role4 = new Text("\nkicked off");
|
||||||
} else {
|
} else {
|
||||||
role4 = new Text("\n" + roles[0]);
|
role4 = new Text("\n" + roles[4]);
|
||||||
}
|
}
|
||||||
role4.setStyle("-fx-font: 25 arial;");
|
role4.setStyle("-fx-font: 25 arial;");
|
||||||
role4.setFill(Color.WHITE);
|
role4.setFill(Color.WHITE);
|
||||||
@ -300,7 +300,7 @@ public class GameController implements Initializable{
|
|||||||
if(kickedOff[5]) {
|
if(kickedOff[5]) {
|
||||||
role5 = new Text("\nkicked off");
|
role5 = new Text("\nkicked off");
|
||||||
} else {
|
} else {
|
||||||
role5 = new Text("\n" + roles[0]);
|
role5 = new Text("\n" + roles[5]);
|
||||||
}
|
}
|
||||||
role5.setStyle("-fx-font: 25 arial;");
|
role5.setStyle("-fx-font: 25 arial;");
|
||||||
role5.setFill(Color.WHITE);
|
role5.setFill(Color.WHITE);
|
||||||
|
|||||||
Reference in New Issue
Block a user