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,9 +86,7 @@ public class Game implements Runnable {
* Initializes new thread that constantly sends a gameState update to all clients in this game * Initializes new thread that constantly sends a gameState update to all clients in this game
*/ */
public void gameStateModelUpdater(){ public void gameStateModelUpdater(){
new Thread(new Runnable() { new Thread(() -> {
@Override
public void run() {
while (getGame().isOngoing) { while (getGame().isOngoing) {
for (Passenger passenger : getGameState().getPassengerTrain()) { for (Passenger passenger : getGameState().getPassengerTrain()) {
passenger.send(GuiParameters.updateGameState, getGame()); passenger.send(GuiParameters.updateGameState, getGame());
@ -99,7 +97,6 @@ public class Game implements Runnable {
e.printStackTrace(); e.printStackTrace();
} }
} }
}
}).start(); }).start();
} }

View File

@ -342,8 +342,8 @@ public class Client {
case GuiParameters.listOfPLayers: case GuiParameters.listOfPLayers:
break; break;
default: default:
gameController.addMessageToNotificationText( notificationTextDisplay(data);
data); //TODO(Sebi,Seraina): should the gameController be in the Application just like the ChatController? //TODO(Sebi,Seraina): should the gameController be in the Application just like the ChatController?
} }
} catch (Exception e) { } catch (Exception e) {
LOGGER.warn("Communication with GUI currently not possible: " + e.getMessage()); 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) { public void determineNoiseDisplay(int position) {
switch (position) { switch (position) {
case 0: case 0:

View File

@ -167,6 +167,13 @@ public class GameController {
//TODO: Wait for a certain time, then clear all again //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 * Updates the labels of the rooms accordingly to the datastructures in GameStateModel
*/ */