Implemented the gameState Update parameter of the the printToGUI message in client, with its needed methods
This commit is contained in:
parent
f058eabb75
commit
c5293bc8ee
@ -11,6 +11,7 @@ import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.GameController;
|
|||||||
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.ClientPinger;
|
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.ClientPinger;
|
||||||
|
|
||||||
|
|
||||||
|
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters;
|
||||||
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
|
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
@ -309,30 +310,31 @@ public class Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* funnels a message to the gui, where depending on the message different functions/controls/methods
|
* funnels a message to the gui, where depending on the parameter different functions/controls/methods
|
||||||
* of the gui are targeted. The message contains information on what to do, which are extracted
|
* of the gui are targeted. The data contains more information the gui needs
|
||||||
* @param msg a message of the form {@code parameter$msg}
|
* @param parameter a string according to {@link GuiParameters} and {@link ClientGameInfoHandler} can be empty
|
||||||
*
|
* @param data some information in a string, separators can be $ or :
|
||||||
|
*TODO(Seraina&Sebi): evtl. auslagern?
|
||||||
*/
|
*/
|
||||||
public void sendToGUI(String msg) {
|
public void sendToGUI(String parameter, String data) {
|
||||||
int indexFirstDollar = msg.indexOf('$');
|
switch (parameter) {
|
||||||
String header = "";
|
case ClientGameInfoHandler.itsNightTime: //ClientGameInfoHandler
|
||||||
try {
|
|
||||||
header = msg.substring(0,indexFirstDollar);
|
|
||||||
} catch (IndexOutOfBoundsException e) {
|
|
||||||
LOGGER.info(e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (header) {
|
|
||||||
case ClientGameInfoHandler.itsNightTime:
|
|
||||||
gameStateModel.setDayClone(false);
|
gameStateModel.setDayClone(false);
|
||||||
break;
|
break;
|
||||||
case ClientGameInfoHandler.itsDayTime:
|
case ClientGameInfoHandler.itsDayTime: //ClientGameInfoHandler
|
||||||
gameStateModel.setDayClone(true);
|
gameStateModel.setDayClone(true);
|
||||||
break;
|
break;
|
||||||
|
case GuiParameters.updateGameState:
|
||||||
|
gameStateModel.setGSFromString(data);
|
||||||
|
break;
|
||||||
|
case GuiParameters.noiseHeardAtPosition:
|
||||||
|
break;
|
||||||
|
case GuiParameters.listOfLobbies:
|
||||||
|
break;
|
||||||
|
case GuiParameters.listOfPLayers:
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
gameController.addMessageToNotificationText(msg); //TODO(Sebi,Seraina): should the gameController be in the Application just like the ChatController?
|
gameController.addMessageToNotificationText(data); //TODO(Sebi,Seraina): should the gameController be in the Application just like the ChatController?
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,7 +49,6 @@ public class JClientProtocolParser {
|
|||||||
break;
|
break;
|
||||||
case Protocol.serverRequestsGhostVote:
|
case Protocol.serverRequestsGhostVote:
|
||||||
LOGGER.debug("Ghost received Vote request");
|
LOGGER.debug("Ghost received Vote request");
|
||||||
//c.sendToGUI(ClientGameInfoHandler.ghostVoteRequest);
|
|
||||||
c.positionSetter(msg.substring(6));
|
c.positionSetter(msg.substring(6));
|
||||||
break;
|
break;
|
||||||
case Protocol.serverRequestsHumanVote:
|
case Protocol.serverRequestsHumanVote:
|
||||||
@ -63,8 +62,8 @@ public class JClientProtocolParser {
|
|||||||
case Protocol.printToGUI:
|
case Protocol.printToGUI:
|
||||||
String substring = msg.substring(6);
|
String substring = msg.substring(6);
|
||||||
int index = msg.indexOf("$");
|
int index = msg.indexOf("$");
|
||||||
String parameter;
|
String parameter = "";
|
||||||
String data;
|
String data = substring;
|
||||||
try {
|
try {
|
||||||
parameter = msg.substring(0,index);
|
parameter = msg.substring(0,index);
|
||||||
data = msg.substring(index+1);
|
data = msg.substring(index+1);
|
||||||
|
|||||||
@ -1,10 +1,18 @@
|
|||||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui;
|
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui;
|
||||||
|
|
||||||
|
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
||||||
|
import ch.unibas.dmi.dbis.cs108.gamelogic.ServerGameInfoHandler;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Class that saves the current game State of the Game the client is in. Should get updated regularly
|
* A Class that saves the current game State of the Game the client is in. Should get updated regularly
|
||||||
* The gui gets its game information from here
|
* The gui gets its game information from here
|
||||||
*/
|
*/
|
||||||
public class GameStateModel {
|
public class GameStateModel {
|
||||||
|
public static final Logger LOGGER = LogManager.getLogger(GameStateModel.class);
|
||||||
|
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
||||||
|
|
||||||
private int nrOfPlayers; //sets the length of the train
|
private int nrOfPlayers; //sets the length of the train
|
||||||
/**
|
/**
|
||||||
* true if it is the day
|
* true if it is the day
|
||||||
@ -79,4 +87,42 @@ public class GameStateModel {
|
|||||||
public boolean getDayClone() {
|
public boolean getDayClone() {
|
||||||
return isDayClone;
|
return isDayClone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setKickedOff(boolean[] kickedOff) {
|
||||||
|
this.kickedOff = kickedOff;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean[] getKickedOff() {
|
||||||
|
return kickedOff;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts information of a String and fills the information into the passengerTrainClone and
|
||||||
|
* kickedOff fields of this gameState
|
||||||
|
* @param data the data in the form: {@code name:role:kickedOff$name:role:kickedOff$}..usw.
|
||||||
|
*/
|
||||||
|
public void setGSFromString(String data) {
|
||||||
|
try {
|
||||||
|
String[] names = new String[6];
|
||||||
|
String[] roles = new String[6];
|
||||||
|
boolean[] kickedOff = new boolean[6];
|
||||||
|
int i = 0;
|
||||||
|
while (!data.isEmpty()) {
|
||||||
|
int index = data.indexOf('$');
|
||||||
|
String left = data.substring(0, index);
|
||||||
|
data = data.substring(index + 1);
|
||||||
|
int j = left.indexOf(':');
|
||||||
|
names[i] = left.substring(0, j);
|
||||||
|
String right = left.substring(j + 1);
|
||||||
|
j = right.indexOf(':');
|
||||||
|
roles[i] = right.substring(0, j);
|
||||||
|
kickedOff[i] = Boolean.parseBoolean(right.substring(j + 1));
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
setPassengerTrainClone(names, roles);
|
||||||
|
setKickedOff(kickedOff);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.warn("data has wrong format");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user