Added an option do delete message in notificationText in GameController again

This commit is contained in:
Seraina 2022-04-30 15:30:03 +02:00
parent 421074a59b
commit 227cfdbedd
3 changed files with 36 additions and 14 deletions

View File

@ -86,18 +86,15 @@ public class Game implements Runnable {
* Initializes new thread that constantly sends a gameState update to all clients in this game
*/
public void gameStateModelUpdater(){
new Thread(new Runnable() {
@Override
public void run() {
while (getGame().isOngoing) {
for (Passenger passenger : getGameState().getPassengerTrain()) {
passenger.send(GuiParameters.updateGameState, getGame());
}
try {
Thread.sleep(1000); //TODO: Is this a good intervall?
} catch (InterruptedException e) {
e.printStackTrace();
}
new Thread(() -> {
while (getGame().isOngoing) {
for (Passenger passenger : getGameState().getPassengerTrain()) {
passenger.send(GuiParameters.updateGameState, getGame());
}
try {
Thread.sleep(1000); //TODO: Is this a good intervall?
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();

View File

@ -342,8 +342,8 @@ public class Client {
case GuiParameters.listOfPLayers:
break;
default:
gameController.addMessageToNotificationText(
data); //TODO(Sebi,Seraina): should the gameController be in the Application just like the ChatController?
notificationTextDisplay(data);
//TODO(Sebi,Seraina): should the gameController be in the Application just like the ChatController?
}
} catch (Exception e) {
LOGGER.warn("Communication with GUI currently not possible: " + e.getMessage());
@ -352,6 +352,24 @@ public class Client {
}
/**
* Starts a new thread, thad adds a message to notificationText in the gameController,
* waits 3 seconds and deletes it again.
* @param data the message to be added
*/
public void notificationTextDisplay(String data) {
new Thread(() -> {
gameController.addMessageToNotificationText(data);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
gameController.clearNotificationText();
}).start();
}
public void determineNoiseDisplay(int position) {
switch (position) {
case 0:

View File

@ -167,6 +167,13 @@ public class GameController {
//TODO: Wait for a certain time, then clear all again
}
/**
* Clears all children from notificationText TextFlow
*/
public void clearNotificationText() {
notificationText.getChildren().clear();
}
/**
* Updates the labels of the rooms accordingly to the datastructures in GameStateModel
*/