Merge remote-tracking branch 'origin/Application' into Application

# Conflicts:
#	src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java
#	src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/ChatApp.java
#	src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/GUI.java
#	src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/GuiParameters.java
This commit is contained in:
Sebastian Lenzlinger 2022-05-01 08:56:55 +02:00
commit ff33163cb6
19 changed files with 435 additions and 171 deletions

View File

@ -1 +1,3 @@
B B
serai
serai

View File

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

View File

@ -17,8 +17,8 @@ public class ClientGameInfoHandler {
public static final String ghostVoteRequest = "Vote on who to ghostify!"; public static final String ghostVoteRequest = "Vote on who to ghostify!";
public static final String humanVoteRequest = "Vote for a ghost to kick off!"; public static final String humanVoteRequest = "Vote for a ghost to kick off!";
public static final String noiseNotification = "Someone passed by you "; public static final String noiseNotification = "Someone passed by you ";
public static final String gameOverHumansWin = "Game over: humans win!"; public static final String gameOverHumansWin = "Game over, humans win!";
public static final String gameOverGhostsWin = "Game over: ghosts win!"; public static final String gameOverGhostsWin = "Game over, ghosts win!";
//relevant for gui //relevant for gui
public static final String itsNightTime = "Please wait, ghosts are active"; public static final String itsNightTime = "Please wait, ghosts are active";

View File

@ -95,7 +95,7 @@ public class Game implements Runnable {
passenger.send(GuiParameters.updateGameState, getGame()); passenger.send(GuiParameters.updateGameState, getGame());
} }
try { try {
Thread.sleep(4000); //TODO: Is this a good intervall? Thread.sleep(2000); //TODO: Is this a good intervall?
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -148,19 +148,22 @@ public class Game implements Runnable {
} }
LOGGER.info(gameState.toString()); LOGGER.info(gameState.toString());
gameStateModelUpdater(); //TODO: does that work? gameStateModelUpdater(); //TODO: does that work?
for(Passenger passenger : gameState.getPassengerTrain()) {
passenger.send(Protocol.positionOfClient + "$" + passenger.getPosition(), this);
}
lobby.getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + "$" + GuiParameters.night + "$");
i = 0; i = 0;
while (isOngoing) {//game cycle TODO: maybe check that more often inside game loop?! while (isOngoing) {//game cycle TODO: maybe check that more often inside game loop?!
if (!isDay) { if (!isDay) {
LOGGER.info("NIGHT"); LOGGER.info("NIGHT");
gameOverCheck = voteHandler.ghostVote(gameState.getPassengerTrain(), this); gameOverCheck = voteHandler.ghostVote(gameState.getPassengerTrain(), this);
setDay(true); setDay(true);
lobby.getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + "$" + ClientGameInfoHandler.itsDayTime + "$"); lobby.getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + "$" + GuiParameters.day + "$");
} else { } else {
LOGGER.info("DAY"); LOGGER.info("DAY");
gameOverCheck = voteHandler.humanVote(gameState.getPassengerTrain(), this); gameOverCheck = voteHandler.humanVote(gameState.getPassengerTrain(), this);
setDay(false); setDay(false);
lobby.getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + "$" + ClientGameInfoHandler.itsNightTime + "$"); lobby.getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + "$" + GuiParameters.night + "$");
} }
if (gameOverCheck.equals(ClientGameInfoHandler.gameOverGhostsWin) || gameOverCheck.equals( if (gameOverCheck.equals(ClientGameInfoHandler.gameOverGhostsWin) || gameOverCheck.equals(
ClientGameInfoHandler.gameOverHumansWin)) { ClientGameInfoHandler.gameOverHumansWin)) {
@ -169,6 +172,9 @@ public class Game implements Runnable {
} }
lobby.getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + "$" + GuiParameters.viewChangeToLobby + "$"); lobby.getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + "$" + GuiParameters.viewChangeToLobby + "$");
lobby.getAdmin().broadcastAnnouncementToLobby(gameOverCheck); lobby.getAdmin().broadcastAnnouncementToLobby(gameOverCheck);
isOngoing = false;
Timer.ghostAfterVoteTimer();
isOngoing = true;
lobby.removeGameFromRunningGames(this); lobby.removeGameFromRunningGames(this);
lobby.addGameToFinishedGames(this); lobby.addGameToFinishedGames(this);
return; return;

View File

@ -167,13 +167,14 @@ public class GameState {
} else if (array[i].getIsGhost()) { } else if (array[i].getIsGhost()) {
print[i] = array[i].getName() + ":g:" + array[i].getKickedOff(); print[i] = array[i].getName() + ":g:" + array[i].getKickedOff();
} else { } else {
print[i] = "| " + array[i].getName() + ":h:" + array[i].getKickedOff(); print[i] = array[i].getName() + ":h:" + array[i].getKickedOff();
} }
} }
for (int i = 0; i < array.length; i++) { for (int i = 0; i < array.length; i++) {
stringBuilder.append("$").append(print[i]); stringBuilder.append("$").append(print[i]);
} }
stringBuilder.append("$");
return stringBuilder.toString(); return stringBuilder.toString();
} }
@ -194,6 +195,7 @@ public class GameState {
for (int i = 0; i < array.length; i++) { for (int i = 0; i < array.length; i++) {
stringBuilder.append("$").append(print[i]); stringBuilder.append("$").append(print[i]);
} }
stringBuilder.append("$");
return stringBuilder.toString(); return stringBuilder.toString();
} }

View File

@ -30,12 +30,10 @@ public class ServerGameInfoHandler {
public static String format(String msg, Passenger passenger, Game game) { public static String format(String msg, Passenger passenger, Game game) {
switch (msg) { switch (msg) {
case ClientGameInfoHandler.ghostVoteRequest: case ClientGameInfoHandler.ghostVoteRequest:
msg = Protocol.serverRequestsGhostVote + "$" + passenger.getPosition() + "$" msg = Protocol.serverRequestsGhostVote + "$" + passenger.getPosition() + "$";
+ game.gameState.toString();
break; break;
case ClientGameInfoHandler.humanVoteRequest: case ClientGameInfoHandler.humanVoteRequest:
msg = Protocol.serverRequestsHumanVote + "$" + passenger.getPosition() + "$" msg = Protocol.serverRequestsHumanVote + "$" + passenger.getPosition() + "$";
+ game.gameState.humanToString();
break; break;
default: default:
msg = Protocol.printToClientConsole + "$" + msg; msg = Protocol.printToClientConsole + "$" + msg;
@ -56,11 +54,11 @@ public class ServerGameInfoHandler {
switch (msg) { switch (msg) {
case ClientGameInfoHandler.ghostVoteRequest: case ClientGameInfoHandler.ghostVoteRequest:
case ClientGameInfoHandler.itsNightTime: case ClientGameInfoHandler.itsNightTime:
msg = Protocol.printToClientConsole + "$Ghosts are voting: " + game.gameState.toString(); msg = Protocol.printToClientConsole + "$Ghosts are voting";
break; break;
case ClientGameInfoHandler.humanVoteRequest: case ClientGameInfoHandler.humanVoteRequest:
case ClientGameInfoHandler.itsDayTime: case ClientGameInfoHandler.itsDayTime:
msg = Protocol.printToClientConsole + "$Humans are voting:" + game.gameState.toString(); msg = Protocol.printToClientConsole + "$Humans are voting";
break; break;
case GuiParameters.updateGameState: case GuiParameters.updateGameState:
msg = Protocol.printToGUI + "$" + GuiParameters.updateGameState + game.getGameState().toString(); msg = Protocol.printToGUI + "$" + GuiParameters.updateGameState + game.getGameState().toString();
@ -114,9 +112,10 @@ public class ServerGameInfoHandler {
case ClientGameInfoHandler.noiseNotification + 5 + " time(s)": case ClientGameInfoHandler.noiseNotification + 5 + " time(s)":
String outMsg = npc.getName() + ": " + noiseRandomizer(); String outMsg = npc.getName() + ": " + noiseRandomizer();
//TODO: add likelyhood //TODO: add likelyhood
Timer.ghostAfterVoteTimer();
game.getLobby().getAdmin().broadcastNpcChatMessageToLobby(outMsg); game.getLobby().getAdmin().broadcastNpcChatMessageToLobby(outMsg);
game.getLobby().getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + GuiParameters.noiseHeardAtPosition game.getLobby().getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + "$" + GuiParameters.noiseHeardAtPosition
+ "$" + npc.getPosition() + "$"); + "$" + npc.getPosition());
break; break;
case ClientGameInfoHandler.ghostVoteRequest: case ClientGameInfoHandler.ghostVoteRequest:
npc.vote(game); npc.vote(game);
@ -138,9 +137,10 @@ public class ServerGameInfoHandler {
case ClientGameInfoHandler.noiseNotification + 4 + " time(s)": case ClientGameInfoHandler.noiseNotification + 4 + " time(s)":
case ClientGameInfoHandler.noiseNotification + 5 + " time(s)": case ClientGameInfoHandler.noiseNotification + 5 + " time(s)":
String outMsg = npc.getName() + ": " + noiseRandomizer(); String outMsg = npc.getName() + ": " + noiseRandomizer();
Timer.ghostAfterVoteTimer();
game.getLobby().getAdmin().broadcastNpcChatMessageToLobby(outMsg); game.getLobby().getAdmin().broadcastNpcChatMessageToLobby(outMsg);
game.getLobby().getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + GuiParameters.noiseHeardAtPosition game.getLobby().getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + "$" + GuiParameters.noiseHeardAtPosition
+ "$" + npc.getPosition() + "$"); + "$" + npc.getPosition());
break; break;
case ClientGameInfoHandler.humanVoteRequest: case ClientGameInfoHandler.humanVoteRequest:
npc.vote(game); npc.vote(game);

View File

@ -22,7 +22,7 @@ public class Timer {
* The length of time in seconds after the ghost vote during which the ghosts visually walk to / * The length of time in seconds after the ghost vote during which the ghosts visually walk to /
* from their victim and the timespan within which humans will hear a noise. After this, the day starts. * from their victim and the timespan within which humans will hear a noise. After this, the day starts.
*/ */
public static final int ghostAfterVoteTime = 7; public static final int ghostAfterVoteTime = 4;
/** /**
* The maximum length of the human vote in the day, in seconds * The maximum length of the human vote in the day, in seconds
*/ */

View File

@ -2,6 +2,8 @@ package ch.unibas.dmi.dbis.cs108.gamelogic;
import ch.unibas.dmi.dbis.cs108.BudaLogConfig; import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
import ch.unibas.dmi.dbis.cs108.gamelogic.klassenstruktur.Passenger; 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.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -66,7 +68,7 @@ public class VoteHandler {
} }
} }
LOGGER.info("Most votes for: " + newGhostPosition); LOGGER.info("Most votes for: " + newGhostPosition);
Timer.ghostAfterVoteTimer();
for(Passenger passenger : passengers) { for(Passenger passenger : passengers) {
if(passenger.getIsGhost() || passenger.getIsSpectator()) { if(passenger.getIsGhost() || passenger.getIsSpectator()) {
passenger.send(passengers[newGhostPosition].getName() + ClientGameInfoHandler.gotGhostyfied, game); passenger.send(passengers[newGhostPosition].getName() + ClientGameInfoHandler.gotGhostyfied, game);
@ -85,7 +87,7 @@ public class VoteHandler {
walk by is being updated. Finally, each passenger receives information about how often he heard something during walk by is being updated. Finally, each passenger receives information about how often he heard something during
this night. The player who's just been ghostified is ignored since he didn't participate in this night's this night. The player who's just been ghostified is ignored since he didn't participate in this night's
ghostification. */ ghostification. */
Timer.ghostAfterVoteTimer();
int[] noiseAmount = new int[6]; int[] noiseAmount = new int[6];
for (int i = 0; i < passengers.length; i++) { for (int i = 0; i < passengers.length; i++) {
if (passengers[i].getIsGhost() && i != newGhostPosition) { if (passengers[i].getIsGhost() && i != newGhostPosition) {
@ -152,6 +154,7 @@ public class VoteHandler {
} }
Timer.humanVoteTimer(game); Timer.humanVoteTimer(game);
game.getLobby().getAdmin().sendMsgToClientsInLobby(Protocol.printToGUI + "$" + GuiParameters.VoteIsOver + "$");
int currentMax = humanVoteEvaluation(passengers, votesForPlayers, game.getGameState().getClientVoteData(), game); int currentMax = humanVoteEvaluation(passengers, votesForPlayers, game.getGameState().getClientVoteData(), game);
@ -170,6 +173,7 @@ public class VoteHandler {
ClientGameInfoHandler.humansVotedFor + voteIndex + ClientGameInfoHandler.isAHuman, game); ClientGameInfoHandler.humansVotedFor + voteIndex + ClientGameInfoHandler.isAHuman, game);
} }
} }
Timer.ghostAfterVoteTimer();
if (passengers[voteIndex].getIsGhost()) { // if player is a ghost if (passengers[voteIndex].getIsGhost()) { // if player is a ghost
if (passengers[voteIndex].getIsOG()) { // if ghost is OG --> end game, humans win if (passengers[voteIndex].getIsOG()) { // if ghost is OG --> end game, humans win
System.out.println(ClientGameInfoHandler.gameOverHumansWin); System.out.println(ClientGameInfoHandler.gameOverHumansWin);

View File

@ -5,7 +5,7 @@ import ch.unibas.dmi.dbis.cs108.gamelogic.ClientGameInfoHandler;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.GUI; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.GUI;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.GameStateModel; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.GameStateModel;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatApp; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ChatApp;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatController; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatController;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.GameController; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.GameController;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge.LoungeApp; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge.LoungeApp;
@ -16,6 +16,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.GuiParameters;
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol; import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
import com.google.inject.Guice;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.Socket; import java.net.Socket;
import java.io.*; import java.io.*;
@ -82,6 +83,9 @@ public class Client {
//this.chatGui = new GUI(this.chatApp); //this.chatGui = new GUI(this.chatApp);
clientPinger = new ClientPinger(this, this.socket); clientPinger = new ClientPinger(this, this.socket);
this.gameStateModel = new GameStateModel(); this.gameStateModel = new GameStateModel();
this.chatApp = new ChatApp(new ClientModel(systemName, this));
ChatApp.setGameController(new GameController(ChatApp.getClientModel(), gameStateModel));
this.chatGui = new GUI(this.chatApp);
this.gameController = new GameController(ChatApp.getClientModel(), gameStateModel); this.gameController = new GameController(ChatApp.getClientModel(), gameStateModel);
this.loungeApp = new LoungeApp(ChatApp.getClientModel()); this.loungeApp = new LoungeApp(ChatApp.getClientModel());
//this.loungeGui = new GUI(this.loungeApp); //this.loungeGui = new GUI(this.loungeApp);
@ -159,6 +163,9 @@ public class Client {
} }
public void setPosition(int position) {
this.position = position;
}
/** /**
* Starts a thread which listens for incoming chat messages / other messages that the user has to * Starts a thread which listens for incoming chat messages / other messages that the user has to
@ -340,29 +347,36 @@ public class Client {
*/ */
public void sendToGUI(String parameter, String data) { public void sendToGUI(String parameter, String data) {
try { try {
if(!parameter.equals(GuiParameters.updateGameState)) {
LOGGER.debug("GUI: PARAMETER:" + parameter + ", DATA: " + data);
}
switch (parameter) { switch (parameter) {
case ClientGameInfoHandler.itsNightTime: //ClientGameInfoHandler case GuiParameters.night: //ClientGameInfoHandler
gameStateModel.setDayClone(false); gameStateModel.setDayClone(false);
chatApp.getGameController().setNoiseButtonInvisible();
break; break;
case ClientGameInfoHandler.itsDayTime: //ClientGameInfoHandler case GuiParameters.day: //ClientGameInfoHandler
gameStateModel.setDayClone(true); gameStateModel.setDayClone(true);
break; break;
case GuiParameters.updateGameState: case GuiParameters.updateGameState:
gameStateModel.setGSFromString(data); gameStateModel.setGSFromString(data);
gameController.updateRoomLabels(); chatApp.getGameController().updateRoomLabels();
break; break;
case GuiParameters.noiseHeardAtPosition: case GuiParameters.noiseHeardAtPosition:
try { try {
int position = Integer.parseInt(data); int position = Integer.parseInt(data);
determineNoiseDisplay(position); determineNoiseDisplay(position);
} catch (Exception e) { } catch (Exception e) {
LOGGER.warn("Not a position given for noise"); LOGGER.warn("Not a position given for noise " +e.getMessage());
} }
break; break;
case GuiParameters.listOfLobbies: case GuiParameters.listOfLobbies:
//updateListOfLobbies(data); (commented out due to compiling error) //updateListOfLobbies(data); (commented out due to compiling error)
//TODO //TODO
break; break;
case GuiParameters.VoteIsOver:
chatApp.getGameController().clearAllNoiseDisplay();
break;
case GuiParameters.listOfPLayers: case GuiParameters.listOfPLayers:
updateListOfClients(data); updateListOfClients(data);
//TODO //TODO
@ -418,6 +432,7 @@ public class Client {
int n = arr.length; int n = arr.length;
for (int i = 0; i < n; i = i + 2) { for (int i = 0; i < n; i = i + 2) {
list.add(new SimpleStringProperty(arr[i])); list.add(new SimpleStringProperty(arr[i]));
//ChatController.getClient().addLobbyToList(new SimpleStringProperty(arr[i]));
} }
//TODO //TODO
} }
@ -441,9 +456,9 @@ public class Client {
public void notificationTextDisplay(String data) { public void notificationTextDisplay(String data) {
new Thread(() -> { new Thread(() -> {
try { try {
gameController.addMessageToNotificationText(data); chatApp.getGameController().addMessageToNotificationText(data);
Thread.sleep(3000); Thread.sleep(5000);
gameController.clearNotificationText(); chatApp.getGameController().clearNotificationText();
} catch (InterruptedException e) { } catch (InterruptedException e) {
LOGGER.warn(e.getMessage()); LOGGER.warn(e.getMessage());
} }
@ -452,19 +467,26 @@ public class Client {
} }
public void determineNoiseDisplay(int position) { public void determineNoiseDisplay(int position) {
LOGGER.debug(position);
switch (position) { switch (position) {
case 0: case 0:
gameController.noiseDisplay0(); chatApp.getGameController().noiseDisplay0();
break;
case 1: case 1:
gameController.noiseDisplay1(); chatApp.getGameController().noiseDisplay1();
break;
case 2: case 2:
gameController.noiseDisplay2(); chatApp.getGameController().noiseDisplay2();
break;
case 3: case 3:
gameController.noiseDisplay3(); chatApp.getGameController().noiseDisplay3();
break;
case 4: case 4:
gameController.noiseDisplay4(); chatApp.getGameController().noiseDisplay4();
break;
case 5: case 5:
gameController.noiseDisplay5(); chatApp.getGameController().noiseDisplay5();
break;
} }
} }

View File

@ -2,6 +2,7 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.client;
import ch.unibas.dmi.dbis.cs108.BudaLogConfig; import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
import ch.unibas.dmi.dbis.cs108.gamelogic.ClientGameInfoHandler; import ch.unibas.dmi.dbis.cs108.gamelogic.ClientGameInfoHandler;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.GameController;
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol; import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
@ -39,6 +40,9 @@ public class JClientProtocolParser {
break; break;
case Protocol.printToClientConsole: case Protocol.printToClientConsole:
System.out.println(msg.substring(6)); System.out.println(msg.substring(6));
if (!msg.substring(6).equals("Your vote was invalid")) {
c.notificationTextDisplay(msg.substring(6));
}
break; break;
case Protocol.printToClientChat: case Protocol.printToClientChat:
//todo: handle chat separately from console. //todo: handle chat separately from console.
@ -72,6 +76,13 @@ public class JClientProtocolParser {
} }
c.sendToGUI(parameter,data); c.sendToGUI(parameter,data);
break; break;
case Protocol.positionOfClient:
try {
int position = Integer.parseInt(msg.substring(6));
GameController.getClient().getClient().setPosition(position);
} catch (Exception e) {
LOGGER.warn(msg.substring(6));
}
default: default:
System.out.println("Received unknown command"); System.out.println("Received unknown command");
} }

View File

@ -2,11 +2,11 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat;
import ch.unibas.dmi.dbis.cs108.BudaLogConfig; import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge.LoungeSceneViewController;
import java.net.URL; import java.net.URL;
import java.util.Objects; import java.util.Objects;
import javafx.application.Application; import javafx.application.Application;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent; import javafx.scene.Parent;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.stage.Stage; import javafx.stage.Stage;
@ -20,7 +20,9 @@ public class ChatApp extends Application {
private static ClientModel clientModel; private static ClientModel clientModel;
private static ChatController chatController; private static ChatController chatController;
private static GameController gameController;
private ClientModel cModel; private ClientModel cModel;
private GameController gameC;
private static LoungeSceneViewController loungeSceneViewController; private static LoungeSceneViewController loungeSceneViewController;
@ -53,10 +55,27 @@ public class ChatApp extends Application {
this.cModel = cModel; this.cModel = cModel;
} }
public void setGameC(GameController gameC) {
this.gameC = gameC;
}
public ClientModel getcModel() { public ClientModel getcModel() {
return cModel; return cModel;
} }
public static void setGameController(
GameController gameController) {
ChatApp.gameController = gameController;
}
public GameController getGameController() {
return gameController;
}
public GameController getGameC() {
return gameC;
}
public static void setClientModel(ClientModel clientM) { public static void setClientModel(ClientModel clientM) {
clientModel = clientM; clientModel = clientM;
} }
@ -90,29 +109,33 @@ public class ChatApp extends Application {
@Override @Override
public void start(Stage primaryStage) throws Exception { public void start(Stage primaryStage) throws Exception {
this.setcModel(clientModel); this.setcModel(clientModel);
URL resource = ChatApp.class.getResource( this.setGameC(gameController);
"ChatView.fxml"); gameC.setClient(cModel);
if (resource == null) { gameC.setGameStateModel(GameController.getGameStateModel());
System.out.println("File wasnt found"); URL chatResource = ChatApp.class.getResource(
} "chat/ChatView.fxml");
//ChatApp chatApp = new ChatApp(new ClientModel()); URL gameResource = ChatApp.class.getResource(
"game/GameDayAll.fxml");
try { try {
Parent root = FXMLLoader.load( Parent root = FXMLLoader.load(
Objects.requireNonNull(ChatApp.class.getResource( Objects.requireNonNull(gameResource));
"ChatView.fxml")));
// TODO bin chatController.getChatPaneRoot() border to root border for rezising // TODO bin chatController.getChatPaneRoot() border to root border for rezising
Scene scene = new Scene(root); Scene scene = new Scene(root);
scene.setRoot(root); scene.setRoot(root);
primaryStage.setScene(scene); primaryStage.setScene(scene);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
primaryStage.setResizable(false);
Node chat = FXMLLoader.load(
Objects.requireNonNull(chatResource));
primaryStage.setTitle("Night Train To Budapest");
primaryStage.setResizable(true); primaryStage.setResizable(true);
primaryStage.setTitle("Lounge"); primaryStage.setTitle("Chat");
primaryStage.show(); primaryStage.show();
} }
public static void main(String[] args) { public static void main(String[] args) {

View File

@ -2,7 +2,6 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui;
import ch.unibas.dmi.dbis.cs108.BudaLogConfig; import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatApp; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatApp;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.lounge.LoungeApp;
import javafx.application.Application; import javafx.application.Application;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;

View File

@ -117,6 +117,7 @@ public class GameStateModel {
j = right.indexOf(':'); j = right.indexOf(':');
roles[i] = right.substring(0, j); roles[i] = right.substring(0, j);
kickedOff[i] = Boolean.parseBoolean(right.substring(j + 1)); kickedOff[i] = Boolean.parseBoolean(right.substring(j + 1));
LOGGER.info(kickedOff[i]);
i++; i++;
} }
setPassengerTrainClone(names, roles); setPassengerTrainClone(names, roles);

View File

@ -2,6 +2,7 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat;
import ch.unibas.dmi.dbis.cs108.BudaLogConfig; import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ChatApp;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.utils.ChatLabelConfigurator; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.utils.ChatLabelConfigurator;
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol; import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;

View File

@ -1,44 +1,33 @@
package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game; package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.Client; import static javafx.scene.AccessibleRole.PARENT;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ChatApp;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.GameStateModel; 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.helpers.GuiParameters;
import javafx.event.EventHandler;
import ch.unibas.dmi.dbis.cs108.BudaLogConfig; import ch.unibas.dmi.dbis.cs108.BudaLogConfig;
import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel;
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol; import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
import java.net.URL; import java.net.URL;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.ListChangeListener;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.scene.Group; import javafx.scene.Group;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.Label; 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.Image;
import javafx.scene.image.ImageView; import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Background;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.text.Text; import javafx.scene.text.Text;
import javafx.scene.text.TextFlow; import javafx.scene.text.TextFlow;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
public class GameController { public class GameController implements Initializable{
public static final Logger LOGGER = LogManager.getLogger(GameController.class); public static final Logger LOGGER = LogManager.getLogger(GameController.class);
public static final BudaLogConfig l = new BudaLogConfig(LOGGER); public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
@ -47,13 +36,27 @@ public class GameController {
private static GameStateModel gameStateModel; private static GameStateModel gameStateModel;
public GameController() {
super();
}
//TODO(Seraina, Sebi): Same issue as ChatController? do with setters? //TODO(Seraina, Sebi): Same issue as ChatController? do with setters?
public GameController(ClientModel c, GameStateModel g) { public GameController(ClientModel c, GameStateModel g) {
client = c; client = c;
gameStateModel = g; gameStateModel = g;
} }
public void setClient(ClientModel c) {
client = c;
}
public static ClientModel getClient() {
return client;
}
public static GameStateModel getGameStateModel() {
return gameStateModel;
}
@FXML @FXML
private AnchorPane gameBG; private AnchorPane gameBG;
@FXML @FXML
@ -102,14 +105,25 @@ public class GameController {
@FXML @FXML
private Button noiseButton; private Button noiseButton;
@FXML @FXML
private TextFlow notificationText; public TextFlow notificationText;
@FXML
private AnchorPane chatAreaGame;
public void addToChatArea(Node n) {
chatAreaGame.getChildren().add(n);
}
public AnchorPane getChatAreaGame() {
return chatAreaGame;
}
/** /**
* If button 0 is clicked, send the vote message 0 to the server * If button 0 is clicked, send the vote message 0 to the server
*/ */
public void sendVote0() { public void sendVote0() {
client.getClient() client.getClient()
.sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + 0); .sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 0);
} }
/** /**
@ -117,7 +131,7 @@ public class GameController {
*/ */
public void sendVote1() { public void sendVote1() {
client.getClient() client.getClient()
.sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + 1); .sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 1);
} }
/** /**
@ -125,7 +139,7 @@ public class GameController {
*/ */
public void sendVote2() { public void sendVote2() {
client.getClient() client.getClient()
.sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + 2); .sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 2);
} }
/** /**
@ -133,7 +147,7 @@ public class GameController {
*/ */
public void sendVote3() { public void sendVote3() {
client.getClient() client.getClient()
.sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + 3); .sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 3);
} }
/** /**
@ -141,7 +155,7 @@ public class GameController {
*/ */
public void sendVote4() { public void sendVote4() {
client.getClient() client.getClient()
.sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + 4); .sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 4);
} }
/** /**
@ -149,30 +163,52 @@ public class GameController {
*/ */
public void sendVote5() { public void sendVote5() {
client.getClient() client.getClient()
.sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + 5); .sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 5);
} }
/** /**
* Sends a noise message, to the server, should be a gui message? * Sends a noise message, to the server, should be a gui message?
*/ */
public void noise() { public void noise() {
LOGGER.info("Do you even get here");
LOGGER.info(client.getClient());
LOGGER.info(client.getClient().getPosition());
if(client.getClient() == null) {
LOGGER.info("But why???");
}
client.getClient().sendMsgToServer( client.getClient().sendMsgToServer(
Protocol.sendMessageToAllClients + "$" + Protocol.printToGUI + GuiParameters.noiseHeardAtPosition + "$" Protocol.sendMessageToAllClients + "$" + Protocol.printToGUI + "$" +GuiParameters.noiseHeardAtPosition + "$"
+ client.getClient().getPosition()); //TODO: Test!! + 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 * Takes a given message and displays it in the notificationText Flow in the game Scene
* @param msg the message to be displayed * @param msg the message to be displayed
*/ */
public void addMessageToNotificationText(String msg){ public void addMessageToNotificationText(String msg){
LOGGER.trace("addMessage " + msg);
Text notification = new Text(msg); Text notification = new Text(msg);
notification.setFill(Color.BLACK);
notification.setStyle("-fx-font: 50 arial;");
Platform.runLater(new Runnable(){
@Override
public void run() {
try { try {
notificationText.getChildren().clear();
notificationText.getChildren().add(notification); notificationText.getChildren().add(notification);
} catch (Exception e) { } catch (Exception e) {
LOGGER.trace("Not yet initialized"); LOGGER.debug(e.getMessage());
} }
}
});
//TODO: Wait for a certain time, then clear all again //TODO: Wait for a certain time, then clear all again
} }
@ -180,32 +216,98 @@ public class GameController {
* Clears all children from notificationText TextFlow * Clears all children from notificationText TextFlow
*/ */
public void clearNotificationText() { public void clearNotificationText() {
LOGGER.trace("clear notify");
Platform.runLater(new Runnable(){
@Override
public void run() {
try { try {
notificationText.getChildren().clear(); notificationText.getChildren().remove(0);
} catch (Exception e) { } catch (Exception e) {
LOGGER.trace("Not yet initialized"); LOGGER.debug("Not yet initialized");
} }
} }
});
}
/** /**
* Updates the labels of the rooms accordingly to the datastructures in GameStateModel * Updates the labels of the rooms accordingly to the datastructures in GameStateModel
*/ */
public void updateRoomLabels() { public void updateRoomLabels() {
LOGGER.debug("roomlables update");
String[] names = gameStateModel.getPassengerTrainClone()[0]; String[] names = gameStateModel.getPassengerTrainClone()[0];
String[] roles = gameStateModel.getPassengerTrainClone()[1]; String[] roles = gameStateModel.getPassengerTrainClone()[1];
boolean[] kickedOff = gameStateModel.getKickedOff();
Text name0 = new Text(names[0]); Text name0 = new Text(names[0]);
name0.setStyle("-fx-font: 25 arial;");
name0.setFill(Color.WHITE);
Text name1 = new Text(names[1]); Text name1 = new Text(names[1]);
name1.setStyle("-fx-font: 25 arial;");
name1.setFill(Color.WHITE);
Text name2 = new Text(names[2]); Text name2 = new Text(names[2]);
name2.setStyle("-fx-font: 25 arial;");
name2.setFill(Color.WHITE);
Text name3 = new Text(names[3]); Text name3 = new Text(names[3]);
name3.setStyle("-fx-font: 25 arial;");
name3.setFill(Color.WHITE);
Text name4 = new Text(names[4]); Text name4 = new Text(names[4]);
name4.setStyle("-fx-font: 25 arial;");
name4.setFill(Color.WHITE);
Text name5 = new Text(names[5]); Text name5 = new Text(names[5]);
Text role0 = new Text(roles[0]); name5.setStyle("-fx-font: 25 arial;");
Text role1 = new Text(roles[1]); name5.setFill(Color.WHITE);
Text role2 = new Text(roles[2]); Text role0;
Text role3 = new Text(roles[3]); if(kickedOff[0]) {
Text role4 = new Text(roles[4]); role0 = new Text("\nkicked off");
Text role5 = new Text(roles[5]); } 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
public void run() {
try { try {
lableRoom0.getChildren().clear(); lableRoom0.getChildren().clear();
lableRoom0.getChildren().add(name0); lableRoom0.getChildren().add(name0);
@ -229,83 +331,147 @@ public class GameController {
LOGGER.trace("Not yet initialized"); LOGGER.trace("Not yet initialized");
} }
} }
});
}
public Image loadBellImage(){
Image bell = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/DayOpen/bell.png");
return bell;
}
/** /**
* Adds an image of a bell on top of button0 * Adds an image of a bell on top of button0
*/ */
public void noiseDisplay0(){ public void noiseDisplay0(){
Image bell = new Image("ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.DayOpen.bell.png"); LOGGER.debug("noise0 called");
Platform.runLater(new Runnable(){
@Override
public void run() {
try { try {
noiseImage0.setImage(bell); noiseImage0.setImage(loadBellImage());
} catch (Exception e) { } catch (Exception e) {
LOGGER.trace("Not yet initialized"); LOGGER.debug(e.getMessage());
} }
} }
});
}
/** /**
* Adds an image of a bell on top of button1 * Adds an image of a bell on top of button1
*/ */
public void noiseDisplay1(){ public void noiseDisplay1(){
Image bell = new Image("ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.DayOpen.bell.png"); LOGGER.debug("noise1 called");
Platform.runLater(new Runnable(){
@Override
public void run() {
try { try {
noiseImage0.setImage(bell); noiseImage1.setImage(loadBellImage());
} catch (Exception e) { } catch (Exception e) {
LOGGER.trace("Not yet initialized"); LOGGER.debug(e.getMessage());
} }
} }
});
}
/** /**
* Adds an image of a bell on top of button2 * Adds an image of a bell on top of button2
*/ */
public void noiseDisplay2(){ public void noiseDisplay2(){
Image bell = new Image("ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.DayOpen.bell.png"); LOGGER.debug("noise2 called");
Platform.runLater(new Runnable(){
@Override
public void run() {
try { try {
noiseImage0.setImage(bell); noiseImage2.setImage(loadBellImage());
} catch (Exception e) { } catch (Exception e) {
LOGGER.trace("Not yet initialized"); LOGGER.debug(e.getMessage());;
} }
} }
});
}
/** /**
* Adds an image of a bell on top of button3 * Adds an image of a bell on top of button3
*/ */
public void noiseDisplay3(){ public void noiseDisplay3() {
Image bell = new Image("ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.DayOpen.bell.png"); LOGGER.debug("noise3 called");
Platform.runLater(new Runnable() {
@Override
public void run() {
try { try {
noiseImage0.setImage(bell); LOGGER.debug("hello");
noiseImage3.setImage(loadBellImage());
} catch (Exception e) { } catch (Exception e) {
LOGGER.trace("Not yet initialized"); LOGGER.debug(e.getMessage());
} }
} }
});
}
/** /**
* Adds an image of a bell on top of button4 * Adds an image of a bell on top of button4
*/ */
public void noiseDisplay4(){ public void noiseDisplay4() {
Image bell = new Image("ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.DayOpen.bell.png"); LOGGER.debug("noise4 called");
Platform.runLater(new Runnable() {
@Override
public void run() {
try { try {
noiseImage0.setImage(bell); LOGGER.debug("hello");
noiseImage4.setImage(loadBellImage());
} catch (Exception e) { } catch (Exception e) {
LOGGER.trace("Not yet initialized"); LOGGER.debug(e.getMessage());
} }
} }
});
}
/** /**
* Adds an image of a bell on top of button5 * Adds an image of a bell on top of button5
*/ */
public void noiseDisplay5(){ public void noiseDisplay5() {
Image bell = new Image("ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.DayOpen.bell.png"); LOGGER.debug("noise5 called");
Platform.runLater(new Runnable(){
@Override
public void run() {
try { try {
noiseImage0.setImage(bell); noiseImage5.setImage(loadBellImage());
} catch (Exception e) { } catch (Exception e) {
LOGGER.trace("Not yet initialized"); LOGGER.debug(e.getMessage());
} }
} }
});
}
/**
* 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( public void setGameStateModel(
GameStateModel gameStateModel) { GameStateModel gameStateModel) {
GameController.gameStateModel = gameStateModel; GameController.gameStateModel = gameStateModel;
} }
@Override
public void initialize(URL location, ResourceBundle resources) {
ChatApp.setGameController(this);
}
} }

View File

@ -51,6 +51,22 @@ public class GuiParameters {
/** /**
* Tells Gui, that a new Lobby has been created. Form: {@code NLOBBY$<lobbyID>:<Admin Name>} * Tells Gui, that a new Lobby has been created. Form: {@code NLOBBY$<lobbyID>:<Admin Name>}
*/ */
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";
public static final String newLobbyCreated = "NLOBBY"; public static final String newLobbyCreated = "NLOBBY";
/** /**

View File

@ -207,5 +207,11 @@ public class Protocol {
*/ */
public static final String printToGUI = "PTGUI"; public static final String printToGUI = "PTGUI";
/**
* Sends an information to client at which position in the train from the game (0 to 5) they sit, as soon as the game starts
* {@code POSOF$position}
*/
public static final String positionOfClient = "POSOF";
} }

View File

@ -391,9 +391,13 @@ public class ClientHandler implements Runnable {
} }
LOGGER.debug("Vote is:" + vote); LOGGER.debug("Vote is:" + vote);
if (vote != Integer.MAX_VALUE) { //gets MAX_VALUE when the vote wasn't valid if (vote != Integer.MAX_VALUE) { //gets MAX_VALUE when the vote wasn't valid
try {
getLobby().getGame().getGameState().getClientVoteData().setVote(position, vote); getLobby().getGame().getGameState().getClientVoteData().setVote(position, vote);
LOGGER.debug("Player vote: " + vote); LOGGER.debug("Player vote: " + vote);
getLobby().getGame().getGameState().getClientVoteData().setHasVoted(position, true); getLobby().getGame().getGameState().getClientVoteData().setHasVoted(position, true);
} catch (NullPointerException e) {
LOGGER.info("Client not in Lobby");
}
} }
} }

View File

@ -9,18 +9,18 @@
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<?import javafx.scene.text.TextFlow?> <?import javafx.scene.text.TextFlow?>
<AnchorPane id="BG" fx:id="gameBG" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="1080.0" prefWidth="1920.0" styleClass="theme" stylesheets="@GameDay.css" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.GameController"> <AnchorPane id="BG" fx:id="gameBG" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="800.0" prefWidth="1200.0" styleClass="theme" stylesheets="@GameDay.css" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.game.GameController">
<children> <children>
<Group fx:id="roomButtonGroupDay" layoutX="230.5" layoutY="220.0"> <Group fx:id="roomButtonGroupDay" layoutX="230.5" layoutY="220.0">
<children> <children>
<HBox fx:id="notificationHBox" layoutX="50.0" layoutY="-74.0" rotate="12.4"> <HBox fx:id="notificationHBox" layoutX="20.0" layoutY="-55.0" rotate="12.4">
<children> <children>
<ImageView fx:id="noiseImage0" fitHeight="150.0" fitWidth="125.0" pickOnBounds="true" preserveRatio="true" /> <ImageView fx:id="noiseImage0" fitHeight="150.0" fitWidth="125.0" pickOnBounds="true" preserveRatio="true" rotate="-12.4" />
<ImageView fx:id="noiseImage1" fitHeight="150.0" fitWidth="125.0" pickOnBounds="true" preserveRatio="true" /> <ImageView fx:id="noiseImage1" fitHeight="150.0" fitWidth="125.0" pickOnBounds="true" preserveRatio="true" rotate="-12.4" />
<ImageView fx:id="noiseImage2" fitHeight="150.0" fitWidth="125.0" pickOnBounds="true" preserveRatio="true" /> <ImageView fx:id="noiseImage2" fitHeight="150.0" fitWidth="125.0" pickOnBounds="true" preserveRatio="true" rotate="-12.4" />
<ImageView fx:id="noiseImage3" fitHeight="150.0" fitWidth="125.0" pickOnBounds="true" preserveRatio="true" /> <ImageView fx:id="noiseImage3" fitHeight="150.0" fitWidth="125.0" pickOnBounds="true" preserveRatio="true" rotate="-12.4" />
<ImageView fx:id="noiseImage4" fitHeight="150.0" fitWidth="125.0" pickOnBounds="true" preserveRatio="true" /> <ImageView fx:id="noiseImage4" fitHeight="150.0" fitWidth="125.0" pickOnBounds="true" preserveRatio="true" rotate="-12.4" />
<ImageView fx:id="noiseImage5" fitHeight="150.0" fitWidth="125.0" pickOnBounds="true" preserveRatio="true" /> <ImageView fx:id="noiseImage5" fitHeight="150.0" fitWidth="125.0" pickOnBounds="true" preserveRatio="true" rotate="-12.4" />
</children> </children>
</HBox> </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"> <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">
@ -95,22 +95,23 @@
</ImageView> </ImageView>
</graphic> </graphic>
</Button> </Button>
<HBox fx:id="roomLables" alignment="CENTER" layoutY="80.0" prefHeight="62.0" prefWidth="747.0" rotate="12.4"> <HBox fx:id="roomLables" alignment="CENTER" layoutY="82.0" prefHeight="62.0" prefWidth="747.0" rotate="12.2">
<children> <children>
<TextFlow fx:id="lableRoom0" prefHeight="200.0" prefWidth="200.0" /> <TextFlow fx:id="lableRoom0" prefHeight="200.0" prefWidth="200.0" textAlignment="CENTER" />
<TextFlow fx:id="lableRoom1" prefHeight="200.0" prefWidth="200.0" /> <TextFlow fx:id="lableRoom1" prefHeight="200.0" prefWidth="200.0" textAlignment="CENTER" />
<TextFlow fx:id="lableRoom2" prefHeight="200.0" prefWidth="200.0" /> <TextFlow fx:id="lableRoom2" prefHeight="200.0" prefWidth="200.0" textAlignment="CENTER" />
<TextFlow fx:id="lableRoom3" prefHeight="200.0" prefWidth="200.0" /> <TextFlow fx:id="lableRoom3" prefHeight="200.0" prefWidth="200.0" textAlignment="CENTER" />
<TextFlow fx:id="lableRoom4" prefHeight="200.0" prefWidth="200.0" /> <TextFlow fx:id="lableRoom4" prefHeight="200.0" prefWidth="200.0" textAlignment="CENTER" />
<TextFlow fx:id="lableRoom5" prefHeight="200.0" prefWidth="200.0" /> <TextFlow fx:id="lableRoom5" prefHeight="200.0" prefWidth="200.0" textAlignment="CENTER" />
</children> </children>
</HBox> </HBox>
</children> </children>
</Group> </Group>
<Button fx:id="noiseButton" alignment="CENTER" layoutX="267.0" layoutY="636.0" mnemonicParsing="false" onAction="#noise" prefHeight="114.0" prefWidth="217.0" text="I heard some noise"> <Button fx:id="noiseButton" alignment="CENTER" layoutX="267.0" layoutY="610.0" mnemonicParsing="false" onAction="#noise" prefHeight="114.0" prefWidth="217.0" text="I heard some noise">
<font> <font>
<Font name="System Bold" size="21.0" /> <Font name="System Bold" size="21.0" />
</font></Button> </font></Button>
<TextFlow fx:id="notificationText" layoutX="581.0" layoutY="386.0" prefHeight="200.0" prefWidth="800.0" textAlignment="CENTER" /> <TextFlow fx:id="notificationText" accessibleRole="PARENT" layoutX="210.0" layoutY="20.0" prefHeight="200.0" prefWidth="800.0" textAlignment="CENTER" />
<AnchorPane fx:id="chatAreaGame" layoutY="738.0" prefHeight="342.0" prefWidth="1920.0" />
</children> </children>
</AnchorPane> </AnchorPane>