The game is now playable wia the game gui, there are still some quirks to work out, especially timing wise and with the POSOF network message
This commit is contained in:
@@ -14,6 +14,7 @@ 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 com.google.inject.Guice;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
import java.io.*;
|
||||
@@ -329,13 +330,17 @@ public class Client {
|
||||
*/
|
||||
public void sendToGUI(String parameter, String data) {
|
||||
try {
|
||||
LOGGER.debug("GUI: PARAMETER:" + parameter + ", DATA: " + data);
|
||||
if(!parameter.equals(GuiParameters.updateGameState)) {
|
||||
LOGGER.debug("GUI: PARAMETER:" + parameter + ", DATA: " + data);
|
||||
}
|
||||
switch (parameter) {
|
||||
case ClientGameInfoHandler.itsNightTime: //ClientGameInfoHandler
|
||||
case GuiParameters.night: //ClientGameInfoHandler
|
||||
gameStateModel.setDayClone(false);
|
||||
chatApp.getGameController().setNoiseButtonInvisible();
|
||||
break;
|
||||
case ClientGameInfoHandler.itsDayTime: //ClientGameInfoHandler
|
||||
case GuiParameters.day: //ClientGameInfoHandler
|
||||
gameStateModel.setDayClone(true);
|
||||
chatApp.getGameController().setNoiseButtonVisible();
|
||||
break;
|
||||
case GuiParameters.updateGameState:
|
||||
gameStateModel.setGSFromString(data);
|
||||
@@ -353,6 +358,9 @@ public class Client {
|
||||
//updateListOfLobbies(data); (commented out due to compiling error)
|
||||
//TODO
|
||||
break;
|
||||
case GuiParameters.VoteIsOver:
|
||||
chatApp.getGameController().clearAllNoiseDisplay();
|
||||
break;
|
||||
case GuiParameters.listOfPLayers:
|
||||
updateListOfClients(data);
|
||||
//TODO
|
||||
@@ -407,7 +415,7 @@ public class Client {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
chatApp.getGameController().addMessageToNotificationText(data);
|
||||
Thread.sleep(3000);
|
||||
Thread.sleep(5000);
|
||||
chatApp.getGameController().clearNotificationText();
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.warn(e.getMessage());
|
||||
@@ -417,19 +425,26 @@ public class Client {
|
||||
}
|
||||
|
||||
public void determineNoiseDisplay(int position) {
|
||||
LOGGER.debug(position);
|
||||
switch (position) {
|
||||
case 0:
|
||||
chatApp.getGameController().noiseDisplay0();
|
||||
break;
|
||||
case 1:
|
||||
chatApp.getGameController().noiseDisplay1();
|
||||
break;
|
||||
case 2:
|
||||
chatApp.getGameController().noiseDisplay2();
|
||||
break;
|
||||
case 3:
|
||||
chatApp.getGameController().noiseDisplay3();
|
||||
break;
|
||||
case 4:
|
||||
chatApp.getGameController().noiseDisplay4();
|
||||
break;
|
||||
case 5:
|
||||
chatApp.getGameController().noiseDisplay5();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,9 @@ public class JClientProtocolParser {
|
||||
break;
|
||||
case Protocol.printToClientConsole:
|
||||
System.out.println(msg.substring(6));
|
||||
if (!msg.substring(6).equals("Your vote was invalid")) {
|
||||
c.notificationTextDisplay(msg.substring(6));
|
||||
}
|
||||
break;
|
||||
case Protocol.printToClientChat:
|
||||
//todo: handle chat separately from console.
|
||||
@@ -74,9 +77,13 @@ public class JClientProtocolParser {
|
||||
c.sendToGUI(parameter,data);
|
||||
break;
|
||||
case Protocol.positionOfClient:
|
||||
int position = Integer.parseInt(msg.substring(6));
|
||||
GameController.getClient().getClient().setPosition(position);
|
||||
default:
|
||||
try {
|
||||
int position = Integer.parseInt(msg.substring(6));
|
||||
GameController.getClient().getClient().setPosition(position);
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn(msg.substring(6));
|
||||
}
|
||||
default:
|
||||
System.out.println("Received unknown command");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,6 +117,7 @@ public class GameStateModel {
|
||||
j = right.indexOf(':');
|
||||
roles[i] = right.substring(0, j);
|
||||
kickedOff[i] = Boolean.parseBoolean(right.substring(j + 1));
|
||||
LOGGER.info(kickedOff[i]);
|
||||
i++;
|
||||
}
|
||||
setPassengerTrainClone(names, roles);
|
||||
|
||||
@@ -181,6 +181,14 @@ public class GameController implements Initializable{
|
||||
+ client.getClient().getPosition()); //TODO: Test!!
|
||||
}
|
||||
|
||||
public void setNoiseButtonInvisible() {
|
||||
noiseButton.setVisible(false);
|
||||
}
|
||||
|
||||
public void setNoiseButtonVisible() {
|
||||
noiseButton.setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a given message and displays it in the notificationText Flow in the game Scene
|
||||
* @param msg the message to be displayed
|
||||
@@ -197,7 +205,6 @@ public class GameController implements Initializable{
|
||||
notificationText.getChildren().add(notification);
|
||||
} catch (Exception e) {
|
||||
LOGGER.debug(e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -214,7 +221,7 @@ public class GameController implements Initializable{
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
notificationText.getChildren().clear();
|
||||
notificationText.getChildren().remove(0);
|
||||
} catch (Exception e) {
|
||||
LOGGER.debug("Not yet initialized");
|
||||
}
|
||||
@@ -230,18 +237,73 @@ public class GameController implements Initializable{
|
||||
LOGGER.debug("roomlables update");
|
||||
String[] names = gameStateModel.getPassengerTrainClone()[0];
|
||||
String[] roles = gameStateModel.getPassengerTrainClone()[1];
|
||||
boolean[] kickedOff = gameStateModel.getKickedOff();
|
||||
Text name0 = new Text(names[0]);
|
||||
name0.setStyle("-fx-font: 25 arial;");
|
||||
name0.setFill(Color.WHITE);
|
||||
Text name1 = new Text(names[1]);
|
||||
name1.setStyle("-fx-font: 25 arial;");
|
||||
name1.setFill(Color.WHITE);
|
||||
Text name2 = new Text(names[2]);
|
||||
name2.setStyle("-fx-font: 25 arial;");
|
||||
name2.setFill(Color.WHITE);
|
||||
Text name3 = new Text(names[3]);
|
||||
name3.setStyle("-fx-font: 25 arial;");
|
||||
name3.setFill(Color.WHITE);
|
||||
Text name4 = new Text(names[4]);
|
||||
name4.setStyle("-fx-font: 25 arial;");
|
||||
name4.setFill(Color.WHITE);
|
||||
Text name5 = new Text(names[5]);
|
||||
Text role0 = new Text(roles[0]);
|
||||
Text role1 = new Text(roles[1]);
|
||||
Text role2 = new Text(roles[2]);
|
||||
Text role3 = new Text(roles[3]);
|
||||
Text role4 = new Text(roles[4]);
|
||||
Text role5 = new Text(roles[5]);
|
||||
name5.setStyle("-fx-font: 25 arial;");
|
||||
name5.setFill(Color.WHITE);
|
||||
Text role0;
|
||||
if(kickedOff[0]) {
|
||||
role0 = new Text("\nkicked off");
|
||||
} else {
|
||||
role0 = new Text("\n" + roles[0]);
|
||||
}
|
||||
role0.setStyle("-fx-font: 25 arial;");
|
||||
role0.setFill(Color.WHITE);
|
||||
Text role1;
|
||||
if(kickedOff[1]) {
|
||||
role1 = new Text("\nkicked off");
|
||||
} else {
|
||||
role1 = new Text("\n" + roles[0]);
|
||||
}
|
||||
role1.setStyle("-fx-font: 25 arial;");
|
||||
role1.setFill(Color.WHITE);
|
||||
Text role2;
|
||||
if(kickedOff[2]) {
|
||||
role2 = new Text("\nkicked off");
|
||||
} else {
|
||||
role2 = new Text("\n" + roles[0]);
|
||||
}
|
||||
role2.setStyle("-fx-font: 25 arial;");
|
||||
role2.setFill(Color.WHITE);
|
||||
Text role3;
|
||||
if(kickedOff[3]) {
|
||||
role3 = new Text("\nkicked off");
|
||||
} else {
|
||||
role3 = new Text("\n" + roles[0]);
|
||||
}
|
||||
role3.setStyle("-fx-font: 25 arial;");
|
||||
role3.setFill(Color.WHITE);
|
||||
Text role4;
|
||||
if(kickedOff[4]) {
|
||||
role4 = new Text("\nkicked off");
|
||||
} else {
|
||||
role4 = new Text("\n" + roles[0]);
|
||||
}
|
||||
role4.setStyle("-fx-font: 25 arial;");
|
||||
role4.setFill(Color.WHITE);
|
||||
Text role5;
|
||||
if(kickedOff[5]) {
|
||||
role5 = new Text("\nkicked off");
|
||||
} else {
|
||||
role5 = new Text("\n" + roles[0]);
|
||||
}
|
||||
role5.setStyle("-fx-font: 25 arial;");
|
||||
role5.setFill(Color.WHITE);
|
||||
|
||||
Platform.runLater(new Runnable(){
|
||||
@Override
|
||||
@@ -368,7 +430,7 @@ public class GameController implements Initializable{
|
||||
/**
|
||||
* Adds an image of a bell on top of button5
|
||||
*/
|
||||
public void noiseDisplay5(){
|
||||
public void noiseDisplay5() {
|
||||
LOGGER.debug("noise5 called");
|
||||
Platform.runLater(new Runnable(){
|
||||
@Override
|
||||
@@ -382,6 +444,27 @@ public class GameController implements Initializable{
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all bells from the view
|
||||
*/
|
||||
public void clearAllNoiseDisplay() {
|
||||
Platform.runLater(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
noiseImage0.setImage(null);
|
||||
noiseImage1.setImage(null);
|
||||
noiseImage2.setImage(null);
|
||||
noiseImage3.setImage(null);
|
||||
noiseImage4.setImage(null);
|
||||
noiseImage5.setImage(null);
|
||||
} catch (Exception e) {
|
||||
LOGGER.debug(e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setGameStateModel(
|
||||
GameStateModel gameStateModel) {
|
||||
GameController.gameStateModel = gameStateModel;
|
||||
|
||||
@@ -40,11 +40,24 @@ public class GuiParameters {
|
||||
*/
|
||||
public static final String viewChangeToGame = "VCGAME";
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Tells, Gui, who the members of a specified Lobby are.
|
||||
* Form: {@code LMEMBS$<lobbyID>$<member names>$..}
|
||||
*/
|
||||
public static String changeToLobby = "LMEMBS";
|
||||
public static final String changeToLobby = "LMEMBS";
|
||||
|
||||
/**
|
||||
* Informs the GUI, that a vote is over
|
||||
*/
|
||||
public static final String VoteIsOver = "VOTEOVER";
|
||||
|
||||
/**
|
||||
* Informes Gui, that its the night
|
||||
*/
|
||||
public static final String night = "NIGHT";
|
||||
/**
|
||||
* Informes Gui, that its the day
|
||||
*/
|
||||
public static final String day = "DAY";
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user