Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
2996f7aca7
@ -1,10 +1,18 @@
|
||||
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
|
||||
* The gui gets its game information from here
|
||||
*/
|
||||
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
|
||||
/**
|
||||
* true if it is the day
|
||||
@ -15,7 +23,7 @@ public class GameStateModel {
|
||||
* can take the values h/g/s for human/ghost/spectator. Safes the role the client this GamesStateModel
|
||||
* lives on currently has
|
||||
*/
|
||||
private String yourRole;
|
||||
private String yourRole; //TODO: Maybe add a GUI field to show this in
|
||||
|
||||
/**
|
||||
* A primitive clone of the passengerTrain in the GameState of the server.
|
||||
@ -79,4 +87,42 @@ public class GameStateModel {
|
||||
public boolean getDayClone() {
|
||||
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