Implemented communication between Server and Client to display a notification if someone else heard a noise
This commit is contained in:
parent
d963c35965
commit
30aab3768d
@ -326,8 +326,15 @@ public class Client {
|
||||
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:
|
||||
break;
|
||||
@ -339,7 +346,23 @@ public class Client {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -70,7 +70,7 @@ public class JClientProtocolParser {
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("No parameter in PTGUI");
|
||||
}
|
||||
|
||||
c.sendToGUI(parameter,data);
|
||||
break;
|
||||
default:
|
||||
System.out.println("Received unknown command");
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game;
|
||||
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.GameStateModel;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters;
|
||||
import javafx.event.EventHandler;
|
||||
import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel;
|
||||
@ -150,7 +151,9 @@ 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 that server understands
|
||||
client.getClient().sendMsgToServer(
|
||||
Protocol.sendMessageToAllClients + "$" + Protocol.printToGUI + GuiParameters.noiseHeardAtPosition + "$"
|
||||
+ client.getClient().getPosition()); //TODO: Test!!
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -112,6 +112,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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user