Commits maybe need to be added to merge with GUI_MilestoneIV is possible

This commit is contained in:
Seraina 2022-04-30 16:52:04 +02:00
parent 81ee9a8841
commit 7109ed113f
16 changed files with 386 additions and 61 deletions

1
OgGhostWinners.txt Normal file
View File

@ -0,0 +1 @@
B

View File

@ -19,7 +19,7 @@ public class BudaLogConfig {
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration config = ctx.getConfiguration();
LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
loggerConfig.setLevel(Level.ERROR); // change level here
loggerConfig.setLevel(Level.INFO); // change level here
ctx.updateLoggers(); // This causes all Loggers to refetch information from their LoggerConfig.
}

View File

@ -8,6 +8,8 @@ import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.HumanNPC;
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.HumanPlayer;
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Passenger;
import ch.unibas.dmi.dbis.cs108.highscore.OgGhostHighScore;
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.server.ClientHandler;
import ch.unibas.dmi.dbis.cs108.multiplayer.server.Lobby;
import java.util.HashSet;
@ -76,6 +78,29 @@ public class Game implements Runnable {
return null;
}
public Game getGame() {
return this;
}
/**
* Initializes new thread that constantly sends a gameState update to all clients in this game
*/
public void gameStateModelUpdater(){
new Thread(() -> {
while (getGame().isOngoing) {
for (Passenger passenger : getGameState().getPassengerTrain()) {
passenger.send(GuiParameters.updateGameState, getGame());
}
try {
Thread.sleep(4000); //TODO: Is this a good intervall?
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
}
/**
* Starts a new game, creates a passenger array and saves it in gameState, sets the OG
* currently at gameState.train[3] fills the passengerTrain moving from left to rigth in the
@ -119,23 +144,27 @@ public class Game implements Runnable {
i++;
}
LOGGER.info(gameState.toString());
gameStateModelUpdater(); //TODO: does that work?
i = 0;
while (isOngoing) {//game cycle
while (isOngoing) {//game cycle TODO: maybe check that more often inside game loop?!
if (!isDay) {
LOGGER.info("NIGHT");
gameOverCheck = voteHandler.ghostVote(gameState.getPassengerTrain(), this);
setDay(true);
lobby.getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + "$" + ClientGameInfoHandler.itsDayTime + "$");
} else {
LOGGER.info("DAY");
gameOverCheck = voteHandler.humanVote(gameState.getPassengerTrain(), this);
setDay(false);
lobby.getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + "$" + ClientGameInfoHandler.itsNightTime + "$");
}
if (gameOverCheck.equals(ClientGameInfoHandler.gameOverGhostsWin) || gameOverCheck.equals(
ClientGameInfoHandler.gameOverHumansWin)) {
if (gameOverCheck.equals(ClientGameInfoHandler.gameOverGhostsWin) && getOgGhost().getIsPlayer()) {
OgGhostHighScore.addOgGhostWinner(getOgGhost().getName());
}
lobby.getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + "$" + GuiParameters.viewChangeToLobby + "$");
lobby.getAdmin().broadcastAnnouncementToLobby(gameOverCheck);
lobby.removeGameFromRunningGames(this);
lobby.addGameToFinishedGames(this);

View File

@ -4,6 +4,7 @@ import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.GhostNPC;
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.HumanNPC;
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Passenger;
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters;
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -48,11 +49,10 @@ public class ServerGameInfoHandler {
* won't get bored Formartiert Nachrichten die für einen Spectator gedacht sind.
*
* @param msg the message to be formatted
* @param passenger the passenger getting the message
* @param game the game in wich the passenger lives
* @return a message in a protocol format
*/
public static String spectatorFormat(String msg, Passenger passenger, Game game) {
public static String spectatorFormat(String msg, Game game) {
switch (msg) {
case ClientGameInfoHandler.ghostVoteRequest:
case ClientGameInfoHandler.itsNightTime:
@ -62,6 +62,9 @@ public class ServerGameInfoHandler {
case ClientGameInfoHandler.itsDayTime:
msg = Protocol.printToClientConsole + "$Humans are voting:" + game.gameState.toString();
break;
case GuiParameters.updateGameState:
msg = Protocol.printToGUI + "$" + GuiParameters.updateGameState + game.getGameState().toString();
break;
default:
msg = Protocol.printToClientConsole + "$" + msg;
}
@ -110,7 +113,10 @@ public class ServerGameInfoHandler {
case ClientGameInfoHandler.noiseNotification + 4 + " time(s)":
case ClientGameInfoHandler.noiseNotification + 5 + " time(s)":
String outMsg = npc.getName() + ": " + noiseRandomizer();
//TODO: add likelyhood
game.getLobby().getAdmin().broadcastNpcChatMessageToLobby(outMsg);
game.getLobby().getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + GuiParameters.noiseHeardAtPosition
+ "$" + npc.getPosition() + "$");
break;
case ClientGameInfoHandler.ghostVoteRequest:
npc.vote(game);
@ -133,6 +139,8 @@ public class ServerGameInfoHandler {
case ClientGameInfoHandler.noiseNotification + 5 + " time(s)":
String outMsg = npc.getName() + ": " + noiseRandomizer();
game.getLobby().getAdmin().broadcastNpcChatMessageToLobby(outMsg);
game.getLobby().getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + GuiParameters.noiseHeardAtPosition
+ "$" + npc.getPosition() + "$");
break;
case ClientGameInfoHandler.humanVoteRequest:
npc.vote(game);

View File

@ -4,6 +4,8 @@ import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
import ch.unibas.dmi.dbis.cs108.gamelogic.ClientVoteData;
import ch.unibas.dmi.dbis.cs108.gamelogic.Game;
import ch.unibas.dmi.dbis.cs108.gamelogic.ServerGameInfoHandler;
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.server.ClientHandler;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -41,7 +43,12 @@ public class GhostPlayer extends Ghost {
*/
@Override
public void send(String msg, Game game) {
String formattedMsg = ServerGameInfoHandler.format(msg, this, game);
String formattedMsg;
if (msg.equals(GuiParameters.updateGameState)) {
formattedMsg = Protocol.printToGUI + "$" + GuiParameters.updateGameState + game.getGameState().toString();
} else {
formattedMsg = ServerGameInfoHandler.format(msg, this, game);
}
clientHandler.sendMsgToClient(formattedMsg);
}

View File

@ -4,6 +4,8 @@ import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
import ch.unibas.dmi.dbis.cs108.gamelogic.ClientVoteData;
import ch.unibas.dmi.dbis.cs108.gamelogic.Game;
import ch.unibas.dmi.dbis.cs108.gamelogic.ServerGameInfoHandler;
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.server.ClientHandler;
import java.util.Arrays;
import org.apache.logging.log4j.LogManager;
@ -42,7 +44,12 @@ public class HumanPlayer extends Human {
*/
@Override
public void send(String msg, Game game) {
String formattedMsg = ServerGameInfoHandler.format(msg,this, game);
String formattedMsg;
if (msg.equals(GuiParameters.updateGameState)) {
formattedMsg = Protocol.printToGUI + "$" + GuiParameters.updateGameState + game.getGameState().humanToString();
} else {
formattedMsg = ServerGameInfoHandler.format(msg, this, game);
}
clientHandler.sendMsgToClient(formattedMsg);
}

View File

@ -29,6 +29,6 @@ public class Spectator extends Passenger{
*/
@Override
public void send(String msg, Game game) {
clientHandler.sendMsgToClient(ServerGameInfoHandler.spectatorFormat(msg, this, game));
clientHandler.sendMsgToClient(ServerGameInfoHandler.spectatorFormat(msg, game));
}
}

View File

@ -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.GuiParameters;
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
import java.net.InetAddress;
@ -309,35 +310,92 @@ public class Client {
}
/**
* funnels a message to the gui, where depending on the message different functions/controls/methods
* of the gui are targeted. The message contains information on what to do, which are extracted
* @param msg a message of the form {@code parameter$msg}
*
* funnels a message to the gui, where depending on the parameter different functions/controls/methods
* of the gui are targeted. The data contains more information the gui needs
* @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) {
int indexFirstDollar = msg.indexOf('$');
String header = "";
public void sendToGUI(String parameter, String data) {
try {
header = msg.substring(0,indexFirstDollar);
} catch (IndexOutOfBoundsException e) {
LOGGER.info(e.getMessage());
}
switch (header) {
case ClientGameInfoHandler.itsNightTime:
gameStateModel.setDayClone(false);
break;
case ClientGameInfoHandler.itsDayTime:
gameStateModel.setDayClone(true);
break;
default:
gameController.addMessageToNotificationText(msg); //TODO(Sebi,Seraina): should the gameController be in the Application just like the ChatController?
switch (parameter) {
case ClientGameInfoHandler.itsNightTime: //ClientGameInfoHandler
gameStateModel.setDayClone(false);
break;
case ClientGameInfoHandler.itsDayTime: //ClientGameInfoHandler
gameStateModel.setDayClone(true);
break;
case GuiParameters.updateGameState:
gameStateModel.setGSFromString(data);
gameController.updateRoomLabels();
break;
case GuiParameters.noiseHeardAtPosition:
try {
int position = Integer.parseInt(data);
determineNoiseDisplay(position);
} catch (Exception e) {
LOGGER.warn("Not a position given for noise");
}
break;
case GuiParameters.listOfLobbies:
//TODO
break;
case GuiParameters.listOfPLayers:
//TODO
break;
case GuiParameters.viewChangeToGame:
//TODO
break;
case GuiParameters.viewChangeToStart:
//TODO
break;
case GuiParameters.viewChangeToLobby:
//TODO
break;
default:
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());
}
}
/**
* 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(() -> {
try {
gameController.addMessageToNotificationText(data);
Thread.sleep(3000);
gameController.clearNotificationText();
} catch (InterruptedException e) {
LOGGER.warn(e.getMessage());
}
}).start();
}
public void determineNoiseDisplay(int position) {
switch (position) {
case 0:
gameController.noiseDisplay0();
case 1:
gameController.noiseDisplay1();
case 2:
gameController.noiseDisplay2();
case 3:
gameController.noiseDisplay3();
case 4:
gameController.noiseDisplay4();
case 5:
gameController.noiseDisplay5();
}
}

View File

@ -49,7 +49,6 @@ public class JClientProtocolParser {
break;
case Protocol.serverRequestsGhostVote:
LOGGER.debug("Ghost received Vote request");
//c.sendToGUI(ClientGameInfoHandler.ghostVoteRequest);
c.positionSetter(msg.substring(6));
break;
case Protocol.serverRequestsHumanVote:
@ -61,7 +60,17 @@ public class JClientProtocolParser {
c.changeUsername(msg.substring(6));
break;
case Protocol.printToGUI:
c.sendToGUI(msg.substring(6));
String substring = msg.substring(6);
int index = msg.indexOf("$");
String parameter = "";
String data = substring;
try {
parameter = msg.substring(0,index);
data = msg.substring(index+1);
} catch (Exception e) {
LOGGER.warn("No parameter in PTGUI");
}
c.sendToGUI(parameter,data);
break;
default:
System.out.println("Received unknown command");

View File

@ -1,5 +1,8 @@
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;
@ -23,6 +26,8 @@ import javafx.scene.control.Label;
import javafx.scene.control.SplitPane;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Background;
import javafx.scene.layout.HBox;
@ -31,13 +36,19 @@ import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.scene.text.TextFlow;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class GameController {
public static final Logger LOGGER = LogManager.getLogger(GameController.class);
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
private static ClientModel client;
private static GameStateModel gameStateModel;
//TODO(Seraina, Sebi): Same issue as ChatController? do with setters?
public GameController(ClientModel c, GameStateModel g) {
client = c;
@ -76,6 +87,20 @@ public class GameController {
@FXML
private TextFlow lableRoom5;
@FXML
private HBox notificationHBox;
@FXML
private ImageView noiseImage0;
@FXML
private ImageView noiseImage1;
@FXML
private ImageView noiseImage2;
@FXML
private ImageView noiseImage3;
@FXML
private ImageView noiseImage4;
@FXML
private ImageView noiseImage5;
@FXML
private Button noiseButton;
@FXML
private TextFlow notificationText;
@ -132,22 +157,29 @@ public class GameController {
* Sends a noise message, to the server, should be a gui message?
*/
public void noise() {
client.getClient().sendMsgToServer("noise"); //TODO: Add message
client.getClient().sendMsgToServer(
Protocol.sendMessageToAllClients + "$" + Protocol.printToGUI + GuiParameters.noiseHeardAtPosition + "$"
+ client.getClient().getPosition()); //TODO: Test!!
}
/**
* Takes a given message and displays it in the notificationText Flow in the game Scene
* @param msg the message to be displayed
*/
public void addMessageToNotificationText(String msg) {
public void addMessageToNotificationText(String msg){
Text notification = new Text(msg);
notificationText.getChildren().clear();
notificationText.getChildren().add(notification);
try {
notificationText.getChildren().clear();
notificationText.getChildren().add(notification);
} catch (Exception e) {
LOGGER.trace("Not yet initialized");
}
//TODO: Wait for a certain time, then clear all again
}
/**
* Updates the labels of the rooms accordingly to the datastructures in GameStateModel
* Adds a msg to the room Lable at the specified position
* @param names a String array containing all the names
*/
public void updateRoomLabels() {
String[] names = gameStateModel.getPassengerTrainClone()[0];
@ -165,26 +197,103 @@ public class GameController {
Text role4 = new Text(roles[4]);
Text role5 = new Text(roles[5]);
lableRoom0.getChildren().clear();
lableRoom0.getChildren().add(name0);
lableRoom0.getChildren().add(role0);
lableRoom1.getChildren().clear();
lableRoom1.getChildren().add(name1);
lableRoom1.getChildren().add(role1);
lableRoom2.getChildren().clear();
lableRoom2.getChildren().add(name2);
lableRoom2.getChildren().add(role2);
lableRoom3.getChildren().clear();
lableRoom3.getChildren().add(name3);
lableRoom3.getChildren().add(role3);
lableRoom4.getChildren().clear();
lableRoom4.getChildren().add(name4);
lableRoom4.getChildren().add(role4);
lableRoom5.getChildren().clear();
lableRoom5.getChildren().add(name5);
lableRoom5.getChildren().add(role5);
try {
lableRoom0.getChildren().clear();
lableRoom0.getChildren().add(name0);
lableRoom0.getChildren().add(role0);
lableRoom1.getChildren().clear();
lableRoom1.getChildren().add(name1);
lableRoom1.getChildren().add(role1);
lableRoom2.getChildren().clear();
lableRoom2.getChildren().add(name2);
lableRoom2.getChildren().add(role2);
lableRoom3.getChildren().clear();
lableRoom3.getChildren().add(name3);
lableRoom3.getChildren().add(role3);
lableRoom4.getChildren().clear();
lableRoom4.getChildren().add(name4);
lableRoom4.getChildren().add(role4);
lableRoom5.getChildren().clear();
lableRoom5.getChildren().add(name5);
lableRoom5.getChildren().add(role5);
} catch (Exception e) {
LOGGER.trace("Not yet initialized");
}
}
/**
* Adds an image of a bell on top of button0
*/
public void noiseDisplay0(){
Image bell = new Image("ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.DayOpen.bell.png");
try {
noiseImage0.setImage(bell);
} catch (Exception e) {
LOGGER.trace("Not yet initialized");
}
}
/**
* Adds an image of a bell on top of button1
*/
public void noiseDisplay1(){
Image bell = new Image("ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.DayOpen.bell.png");
try {
noiseImage0.setImage(bell);
} catch (Exception e) {
LOGGER.trace("Not yet initialized");
}
}
/**
* Adds an image of a bell on top of button2
*/
public void noiseDisplay2(){
Image bell = new Image("ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.DayOpen.bell.png");
try {
noiseImage0.setImage(bell);
} catch (Exception e) {
LOGGER.trace("Not yet initialized");
}
}
/**
* Adds an image of a bell on top of button3
*/
public void noiseDisplay3(){
Image bell = new Image("ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.DayOpen.bell.png");
try {
noiseImage0.setImage(bell);
} catch (Exception e) {
LOGGER.trace("Not yet initialized");
}
}
/**
* Adds an image of a bell on top of button4
*/
public void noiseDisplay4(){
Image bell = new Image("ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.DayOpen.bell.png");
try {
noiseImage0.setImage(bell);
} catch (Exception e) {
LOGGER.trace("Not yet initialized");
}
}
/**
* Adds an image of a bell on top of button5
*/
public void noiseDisplay5(){
Image bell = new Image("ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.DayOpen.bell.png");
try {
noiseImage0.setImage(bell);
} catch (Exception e) {
LOGGER.trace("Not yet initialized");
}
}
public void setGameStateModel(
GameStateModel gameStateModel) {

View File

@ -0,0 +1,45 @@
package ch.unibas.dmi.dbis.cs108.multiplayer.helpers;
/**
* This class contains parameters for the PTGUI protocol message
*/
public class GuiParameters {
/**
* Tells GUI to update the gameStateModel, in the form {@code UPDATE$name:role:kickedOff$name:role:kickedOff} ... usw.
*/
public static final String updateGameState = "UPDATE";
/**
* Tells Gui, that the following statement after $, is a String containing the listOfLobbies
*/
public static final String listOfLobbies = "LOBBIES";
/**
* Tells Gui, that what follows is a list of players per Lobby
*/
public static final String listOfPLayers = "PLAYERS";
/**
* Tells Gui, that the passenger at position {@code position} has heard some noise
* Form: {@code NOISE$position$}
*/
public static final String noiseHeardAtPosition = "NOISE";
/**
* Tells Gui, that the start view should be displayed
*/
public static final String viewChangeToStart = "VCSTART";
/**
* Tells Gui, that the lobby view should be displayed
*/
public static final String viewChangeToLobby = "VCLOBBY";
/**
* Tells Gui, that the game view should be displayed
*/
public static final String viewChangeToGame = "VCGAME";
}

View File

@ -143,6 +143,12 @@ public class Protocol {
*/
public static final String highScoreList = "HSCOR";
/**
* The client requests that a message in {@code STACL$msg} is sent to all clients but only the message
* without a specific Server message to be added.
*/
public static final String sendMessageToAllClients = "STACL";
@ -195,10 +201,9 @@ public class Protocol {
public static final String changedUserName = "CHNAM";
/**
* Sends a message to a client containing information for the gui. The command is structured {@code PTGUI$parameter$msg}
* where the parameter specifies what exactly to do in de gui (i.e. change scene) and the optional
* message contains information the gui needs from the server to execute the command specified in the parameter
*
* Handles all information that the gui of the client needs. The Form is {@code PTGUI$parameters$msg}
* where the parameter tells the gui to do different things according to {@link GuiParameters} and the message
* contains a certain information i.e. who is where in the train
*/
public static final String printToGUI = "PTGUI";

View File

@ -238,7 +238,7 @@ public class ClientHandler implements Runnable {
* @param msg the Message to be broadcast. Does not have to be protocol-formatted, this method
* will take care of that.
*/
public static void broadcastAnnouncementToAll(String msg) {
public static void broadcastAnnouncementToAll(String msg) { //TODO: Adjust to GUI command?
System.out.println(msg);
for (ClientHandler client : connectedClients) {
client.sendMsgToClient(Protocol.printToClientConsole + "$" + msg);
@ -254,7 +254,7 @@ public class ClientHandler implements Runnable {
* @param msg the Message to be broadcast. Does not have to be protocol-formatted, this method
* will take care of that.
*/
public void broadcastAnnouncementToLobby(String msg) {
public void broadcastAnnouncementToLobby(String msg) { //TODO: Adjust to GUI command?
Lobby l = getLobby();
if (l != null) {
//System.out.println(msg); we can-comment this if you want lobby-announcements to print on the server console as well.
@ -305,6 +305,35 @@ public class ClientHandler implements Runnable {
}
}
/**
* Sends a given message to all connected client. The message has to already be protocol-formatted.
*
* @param msg the given message. Should already be protocol-formatted.
*/
public void sendMsgToAllClients(String msg) {
for (ClientHandler client : connectedClients) {
client.sendMsgToClient(msg);
}
}
/**
* Sends a Message to all clients in the same lobby. The message has to already be protocol-formatted.
* @param msg the given message. Should already be protocol-formatted.
*/
public void sendMsgToClientsInLobby(String msg) {
Lobby l = getLobby();
if (l != null) {
//System.out.println(msg); we can-comment this if you want lobby-announcements to print on the server console as well.
for (ClientHandler client : l.getLobbyClients()) {
client.sendMsgToClient(msg);
}
} else {
LOGGER.debug("Could not send announcements; probably client isn't in a lobby."
+ "Will send across all lobbies now.");
sendMsgToAllClients(msg);
}
}
/**
* Decode a whisper message
*

View File

@ -2,6 +2,7 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.server;
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
@ -81,6 +82,7 @@ public class JServerProtocolParser {
try {
int i = Integer.parseInt(msg.substring(6, 7));
h.joinLobby(i);
h.sendMsgToClient(Protocol.printToGUI + "$" + GuiParameters.viewChangeToLobby + "$");
} catch (Exception e) {
h.sendMsgToClient(Protocol.printToClientConsole
+ "$Invalid input. Please use JOINL$1 to join Lobby 1, for example.");
@ -88,6 +90,7 @@ public class JServerProtocolParser {
break;
case Protocol.createNewLobby:
h.createNewLobby();
h.sendMsgToClient(Protocol.printToGUI + "$" + GuiParameters.viewChangeToLobby+ "$");
break;
case Protocol.listLobbies:
h.listLobbies();
@ -97,6 +100,7 @@ public class JServerProtocolParser {
break;
case Protocol.leaveLobby:
h.leaveLobby();
h.sendMsgToClient(Protocol.printToGUI + "$" + GuiParameters.viewChangeToStart + "$");
break;
case Protocol.votedFor:
LOGGER.debug("Made it here");
@ -105,6 +109,7 @@ public class JServerProtocolParser {
break;
case Protocol.startANewGame:
h.startNewGame();
h.sendMsgToClientsInLobby(Protocol.printToGUI + "$" + GuiParameters.viewChangeToGame + "$");
break;
case Protocol.listGames:
h.listGames();
@ -112,6 +117,9 @@ public class JServerProtocolParser {
case Protocol.highScoreList:
h.sendHighScoreList();
break;
case Protocol.sendMessageToAllClients:
msg = msg.substring(6);
h.sendMsgToClient(msg);
default:
System.out.println("Received unknown command");
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

@ -13,6 +13,16 @@
<children>
<Group fx:id="roomButtonGroupDay" layoutX="230.5" layoutY="220.0">
<children>
<HBox fx:id="notificationHBox" layoutX="50.0" layoutY="-74.0" rotate="12.4">
<children>
<ImageView fx:id="noiseImage0" fitHeight="150.0" fitWidth="125.0" pickOnBounds="true" preserveRatio="true" />
<ImageView fx:id="noiseImage1" fitHeight="150.0" fitWidth="125.0" pickOnBounds="true" preserveRatio="true" />
<ImageView fx:id="noiseImage2" fitHeight="150.0" fitWidth="125.0" pickOnBounds="true" preserveRatio="true" />
<ImageView fx:id="noiseImage3" fitHeight="150.0" fitWidth="125.0" pickOnBounds="true" preserveRatio="true" />
<ImageView fx:id="noiseImage4" fitHeight="150.0" fitWidth="125.0" pickOnBounds="true" preserveRatio="true" />
<ImageView fx:id="noiseImage5" fitHeight="150.0" fitWidth="125.0" pickOnBounds="true" preserveRatio="true" />
</children>
</HBox>
<Button id="room1" fx:id="buttonRoom0" accessibleRole="RADIO_BUTTON" alignment="TOP_CENTER" contentDisplay="GRAPHIC_ONLY" layoutX="21.5" minWidth="-Infinity" mnemonicParsing="false" onAction="#sendVote0" prefHeight="110.0" prefWidth="90.0" text="room0">
<font>
<Font size="25.0" />