Merge branch 'GUI_MilestoneIV' into 'master'

Started implementing the gui for milestone IV

See merge request cs108-fs22/Gruppe-8!7
This commit is contained in:
Seraina Schöb 2022-04-30 14:58:25 +00:00
commit 71ed59b571
2 changed files with 59 additions and 4 deletions

View File

@ -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");
}
}
}

View File

@ -3,7 +3,6 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.Client;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.GameStateModel;
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.GameStateModel;
import javafx.event.EventHandler;
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel;
@ -178,8 +177,18 @@ public class GameController {
}
/**
* Adds a msg to the room Lable at the specified position
* @param names a String array containing all the names
* Clears all children from notificationText TextFlow
*/
public void clearNotificationText() {
try {
notificationText.getChildren().clear();
} catch (Exception e) {
LOGGER.trace("Not yet initialized");
}
}
/**
* Updates the labels of the rooms accordingly to the datastructures in GameStateModel
*/
public void updateRoomLabels() {
String[] names = gameStateModel.getPassengerTrainClone()[0];