Merge remote-tracking branch 'origin/Application' into Application
This commit is contained in:
commit
39c0d4e52f
@ -31,8 +31,9 @@ public class HumanNPC extends Human {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a msg to the ServerGameInfoHandler.humanNpcParser to decide what has to happen now, if the
|
||||
* npc hasn't been kicked off 8(should never happen to a human though)
|
||||
* Sends a msg to the ServerGameInfoHandler.humanNpcParser to decide what has to happen now, if
|
||||
* the npc hasn't been kicked off 8(should never happen to a human though)
|
||||
*
|
||||
* @param msg the message that is sent to this player.
|
||||
* @param game the game the HumanNPC lives on (in game.gameState.passengerTrain)
|
||||
*/
|
||||
@ -44,22 +45,23 @@ public class HumanNPC extends Human {
|
||||
}
|
||||
|
||||
/**
|
||||
* Currently returns a random integer for voting, but only for passengers that haven't been
|
||||
* kicked off yet
|
||||
* Currently returns a random integer for voting, but only for passengers that haven't been kicked
|
||||
* off yet
|
||||
*
|
||||
* @param game the game this NPC lives on
|
||||
*/
|
||||
public void vote(Game game) {
|
||||
Passenger[] passengers = game.getGameState().getPassengerTrain();
|
||||
int kickedOffCounter = 0;
|
||||
for(Passenger passenger : passengers) {
|
||||
if(passenger.getKickedOff()) {
|
||||
for (Passenger passenger : passengers) {
|
||||
if (passenger.getKickedOff()) {
|
||||
kickedOffCounter++;
|
||||
}
|
||||
}
|
||||
int[] inGamePositions = new int[passengers.length - kickedOffCounter];
|
||||
int i = 0;
|
||||
for(Passenger passenger : passengers) {
|
||||
if(!passenger.getKickedOff()) {
|
||||
for (Passenger passenger : passengers) {
|
||||
if (!passenger.getKickedOff()) {
|
||||
inGamePositions[i] = passenger.getPosition();
|
||||
i++;
|
||||
}
|
||||
@ -67,7 +69,7 @@ public class HumanNPC extends Human {
|
||||
int randomNr = (int) (Math.random() * inGamePositions.length);
|
||||
vote = inGamePositions[randomNr];
|
||||
hasVoted = true;
|
||||
game.getGameState().getClientVoteData().setHasVoted(position,hasVoted);
|
||||
game.getGameState().getClientVoteData().setHasVoted(position, hasVoted);
|
||||
LOGGER.info("HumanNPC at Position: " + this.getPosition() + " has voted for: " + vote);
|
||||
}
|
||||
}
|
||||
|
||||
@ -341,7 +341,7 @@ public class Client {
|
||||
* @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?
|
||||
* TODO(Seraina&Sebi): evtl. auslagern?
|
||||
*/
|
||||
public void sendToGUI(String parameter, String data) {
|
||||
try {
|
||||
@ -385,21 +385,23 @@ public class Client {
|
||||
break;
|
||||
case GuiParameters.viewChangeToGame:
|
||||
chatApp.getLoungeSceneViewController().addGameView();
|
||||
//TODO
|
||||
break;
|
||||
//TODO
|
||||
break;
|
||||
/*case GuiParameters.viewChangeToStart:
|
||||
//TODO
|
||||
break;*/
|
||||
case GuiParameters.viewChangeToLobby:
|
||||
chatApp.getLoungeSceneViewController().removeGameView();
|
||||
//TODO
|
||||
break;
|
||||
//TODO
|
||||
break;
|
||||
case GuiParameters.addNewMemberToLobby:
|
||||
addPlayerToLobby(data);
|
||||
break;
|
||||
case GuiParameters.newLobbyCreated:
|
||||
makeNewLobby(data);
|
||||
break;
|
||||
case GuiParameters.newPlayerOnServer:
|
||||
addNewPlayerToGui(data);
|
||||
default:
|
||||
notificationTextDisplay(data);
|
||||
//TODO(Sebi,Seraina): should the gameController be in the Application just like the ChatController?
|
||||
@ -412,17 +414,22 @@ public class Client {
|
||||
|
||||
}
|
||||
|
||||
private void addNewPlayerToGui(String data) {
|
||||
loungeSceneViewController.addClientToList(data);
|
||||
LOGGER.debug("addNewPlayerToGui() seems to have finished");
|
||||
}
|
||||
|
||||
private void makeNewLobby(String data) {
|
||||
String[] params = data.split(":");
|
||||
loungeSceneViewController.newLobby(params[0], params[1]);
|
||||
LOGGER.debug("makeNewLobby() seems to have finnished");
|
||||
LOGGER.debug("makeNewLobby() seems to have finished");
|
||||
|
||||
}
|
||||
|
||||
private void addPlayerToLobby(String data) {
|
||||
String[] params = data.split(":");
|
||||
loungeSceneViewController.addPlayerToLobby(params[0], params[1]);
|
||||
LOGGER.debug("addPlayerToLobby() seems to have finnished");
|
||||
LOGGER.debug("addPlayerToLobby() seems to have finished");
|
||||
}
|
||||
|
||||
private void updateLobbyMembers(String data) {
|
||||
|
||||
@ -27,451 +27,456 @@ import javafx.scene.text.TextFlow;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class GameController implements Initializable{
|
||||
public static final Logger LOGGER = LogManager.getLogger(GameController.class);
|
||||
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
||||
public class GameController implements Initializable {
|
||||
|
||||
private static ClientModel client;
|
||||
public static final Logger LOGGER = LogManager.getLogger(GameController.class);
|
||||
public static final BudaLogConfig l = new BudaLogConfig(LOGGER);
|
||||
|
||||
private static GameStateModel gameStateModel;
|
||||
private static ClientModel client;
|
||||
|
||||
private static GameStateModel gameStateModel;
|
||||
|
||||
|
||||
public GameController() {
|
||||
super();
|
||||
}
|
||||
//TODO(Seraina, Sebi): Same issue as ChatController? do with setters?
|
||||
public GameController(ClientModel c, GameStateModel g) {
|
||||
client = c;
|
||||
gameStateModel = g;
|
||||
}
|
||||
public GameController() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void setClient(ClientModel c) {
|
||||
client = c;
|
||||
}
|
||||
//TODO(Seraina, Sebi): Same issue as ChatController? do with setters?
|
||||
public GameController(ClientModel c, GameStateModel g) {
|
||||
client = c;
|
||||
gameStateModel = g;
|
||||
}
|
||||
|
||||
public static ClientModel getClient() {
|
||||
return client;
|
||||
}
|
||||
public void setClient(ClientModel c) {
|
||||
client = c;
|
||||
}
|
||||
|
||||
public static GameStateModel getGameStateModel() {
|
||||
return gameStateModel;
|
||||
}
|
||||
public static ClientModel getClient() {
|
||||
return client;
|
||||
}
|
||||
|
||||
@FXML
|
||||
private AnchorPane gameBG;
|
||||
@FXML
|
||||
public static GameStateModel getGameStateModel() {
|
||||
return gameStateModel;
|
||||
}
|
||||
|
||||
@FXML
|
||||
private AnchorPane gameBG;
|
||||
@FXML
|
||||
private Group roomButtonGroupDay;
|
||||
@FXML
|
||||
@FXML
|
||||
private Button buttonRoom0;
|
||||
@FXML
|
||||
@FXML
|
||||
private Button buttonRoom1;
|
||||
@FXML
|
||||
@FXML
|
||||
private Button buttonRoom2;
|
||||
@FXML
|
||||
@FXML
|
||||
private Button buttonRoom3;
|
||||
@FXML
|
||||
@FXML
|
||||
private Button buttonRoom4;
|
||||
@FXML
|
||||
@FXML
|
||||
private Button buttonRoom5;
|
||||
|
||||
@FXML
|
||||
private HBox roomLables;
|
||||
@FXML
|
||||
private TextFlow lableRoom0;
|
||||
@FXML
|
||||
private TextFlow lableRoom1;
|
||||
@FXML
|
||||
private TextFlow lableRoom2;
|
||||
@FXML
|
||||
private TextFlow lableRoom3;
|
||||
@FXML
|
||||
private TextFlow lableRoom4;
|
||||
@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
|
||||
public TextFlow notificationText;
|
||||
@FXML
|
||||
private AnchorPane chatAreaGame;
|
||||
@FXML
|
||||
private HBox roomLables;
|
||||
@FXML
|
||||
private TextFlow lableRoom0;
|
||||
@FXML
|
||||
private TextFlow lableRoom1;
|
||||
@FXML
|
||||
private TextFlow lableRoom2;
|
||||
@FXML
|
||||
private TextFlow lableRoom3;
|
||||
@FXML
|
||||
private TextFlow lableRoom4;
|
||||
@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
|
||||
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
|
||||
*/
|
||||
public void sendVote0() {
|
||||
client.getClient()
|
||||
.sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* If button 1 is clicked, send the vote message 0 to the server
|
||||
*/
|
||||
public void sendVote1() {
|
||||
client.getClient()
|
||||
.sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* If button 2 is clicked, send the vote message 0 to the server
|
||||
*/
|
||||
public void sendVote2() {
|
||||
client.getClient()
|
||||
.sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* If button 3 is clicked, send the vote message 0 to the server
|
||||
*/
|
||||
public void sendVote3() {
|
||||
client.getClient()
|
||||
.sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* If button 4 is clicked, send the vote message 0 to the server
|
||||
*/
|
||||
public void sendVote4() {
|
||||
client.getClient()
|
||||
.sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* If button 5 is clicked, send the vote message 0 to the server
|
||||
*/
|
||||
public void sendVote5() {
|
||||
client.getClient()
|
||||
.sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a noise message, to the server, should be a gui message?
|
||||
*/
|
||||
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???");
|
||||
public void addToChatArea(Node n) {
|
||||
chatAreaGame.getChildren().add(n);
|
||||
}
|
||||
client.getClient().sendMsgToServer(
|
||||
Protocol.sendMessageToAllClients + "$" + Protocol.printToGUI + "$" +GuiParameters.noiseHeardAtPosition + "$"
|
||||
+ 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
|
||||
*/
|
||||
public void addMessageToNotificationText(String msg){
|
||||
LOGGER.trace("addMessage " + 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 {
|
||||
notificationText.getChildren().add(notification);
|
||||
} catch (Exception e) {
|
||||
LOGGER.debug(e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//TODO: Wait for a certain time, then clear all again
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all children from notificationText TextFlow
|
||||
*/
|
||||
public void clearNotificationText() {
|
||||
LOGGER.trace("clear notify");
|
||||
Platform.runLater(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
notificationText.getChildren().remove(0);
|
||||
} catch (Exception e) {
|
||||
LOGGER.debug("Not yet initialized");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the labels of the rooms accordingly to the datastructures in GameStateModel
|
||||
*/
|
||||
public void updateRoomLabels() {
|
||||
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]);
|
||||
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]);
|
||||
public AnchorPane getChatAreaGame() {
|
||||
return chatAreaGame;
|
||||
}
|
||||
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[1]);
|
||||
|
||||
/**
|
||||
* If button 0 is clicked, send the vote message 0 to the server
|
||||
*/
|
||||
public void sendVote0() {
|
||||
client.getClient()
|
||||
.sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 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[2]);
|
||||
|
||||
/**
|
||||
* If button 1 is clicked, send the vote message 0 to the server
|
||||
*/
|
||||
public void sendVote1() {
|
||||
client.getClient()
|
||||
.sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 1);
|
||||
}
|
||||
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[3]);
|
||||
|
||||
/**
|
||||
* If button 2 is clicked, send the vote message 0 to the server
|
||||
*/
|
||||
public void sendVote2() {
|
||||
client.getClient()
|
||||
.sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 2);
|
||||
}
|
||||
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[4]);
|
||||
|
||||
/**
|
||||
* If button 3 is clicked, send the vote message 0 to the server
|
||||
*/
|
||||
public void sendVote3() {
|
||||
client.getClient()
|
||||
.sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 3);
|
||||
}
|
||||
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[5]);
|
||||
|
||||
/**
|
||||
* If button 4 is clicked, send the vote message 0 to the server
|
||||
*/
|
||||
public void sendVote4() {
|
||||
client.getClient()
|
||||
.sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 4);
|
||||
}
|
||||
role5.setStyle("-fx-font: 25 arial;");
|
||||
role5.setFill(Color.WHITE);
|
||||
|
||||
Platform.runLater(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
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");
|
||||
/**
|
||||
* If button 5 is clicked, send the vote message 0 to the server
|
||||
*/
|
||||
public void sendVote5() {
|
||||
client.getClient()
|
||||
.sendMsgToServer(Protocol.votedFor + "$" + client.getClient().getPosition() + "$" + 5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a noise message, to the server, should be a gui message?
|
||||
*/
|
||||
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(
|
||||
Protocol.sendMessageToAllClients + "$" + Protocol.printToGUI + "$"
|
||||
+ GuiParameters.noiseHeardAtPosition + "$"
|
||||
+ client.getClient().getPosition()); //TODO: Test!!
|
||||
}
|
||||
|
||||
public Image loadBellImage(){
|
||||
Image bell = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/DayOpen/bell.png");
|
||||
return bell;
|
||||
}
|
||||
public void setNoiseButtonInvisible() {
|
||||
noiseButton.setVisible(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an image of a bell on top of button0
|
||||
*/
|
||||
public void noiseDisplay0(){
|
||||
LOGGER.debug("noise0 called");
|
||||
Platform.runLater(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
noiseImage0.setImage(loadBellImage());
|
||||
} catch (Exception e) {
|
||||
LOGGER.debug(e.getMessage());
|
||||
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
|
||||
*/
|
||||
public void addMessageToNotificationText(String msg) {
|
||||
LOGGER.trace("addMessage " + 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 {
|
||||
notificationText.getChildren().add(notification);
|
||||
} catch (Exception e) {
|
||||
LOGGER.debug(e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//TODO: Wait for a certain time, then clear all again
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all children from notificationText TextFlow
|
||||
*/
|
||||
public void clearNotificationText() {
|
||||
LOGGER.trace("clear notify");
|
||||
Platform.runLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
notificationText.getChildren().remove(0);
|
||||
} catch (Exception e) {
|
||||
LOGGER.debug("Not yet initialized");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the labels of the rooms accordingly to the datastructures in GameStateModel
|
||||
*/
|
||||
public void updateRoomLabels() {
|
||||
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]);
|
||||
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]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an image of a bell on top of button1
|
||||
*/
|
||||
public void noiseDisplay1(){
|
||||
LOGGER.debug("noise1 called");
|
||||
Platform.runLater(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
noiseImage1.setImage(loadBellImage());
|
||||
} catch (Exception e) {
|
||||
LOGGER.debug(e.getMessage());
|
||||
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[1]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an image of a bell on top of button2
|
||||
*/
|
||||
public void noiseDisplay2(){
|
||||
LOGGER.debug("noise2 called");
|
||||
Platform.runLater(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
noiseImage2.setImage(loadBellImage());
|
||||
} catch (Exception e) {
|
||||
LOGGER.debug(e.getMessage());;
|
||||
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[2]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an image of a bell on top of button3
|
||||
*/
|
||||
public void noiseDisplay3() {
|
||||
LOGGER.debug("noise3 called");
|
||||
Platform.runLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
LOGGER.debug("hello");
|
||||
noiseImage3.setImage(loadBellImage());
|
||||
} catch (Exception e) {
|
||||
LOGGER.debug(e.getMessage());
|
||||
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[3]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an image of a bell on top of button4
|
||||
*/
|
||||
public void noiseDisplay4() {
|
||||
LOGGER.debug("noise4 called");
|
||||
Platform.runLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
LOGGER.debug("hello");
|
||||
noiseImage4.setImage(loadBellImage());
|
||||
} catch (Exception e) {
|
||||
LOGGER.debug(e.getMessage());
|
||||
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[4]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an image of a bell on top of button5
|
||||
*/
|
||||
public void noiseDisplay5() {
|
||||
LOGGER.debug("noise5 called");
|
||||
Platform.runLater(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
noiseImage5.setImage(loadBellImage());
|
||||
} catch (Exception e) {
|
||||
LOGGER.debug(e.getMessage());
|
||||
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[5]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
role5.setStyle("-fx-font: 25 arial;");
|
||||
role5.setFill(Color.WHITE);
|
||||
|
||||
/**
|
||||
* 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());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
Platform.runLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
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");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setGameStateModel(
|
||||
GameStateModel gameStateModel) {
|
||||
GameController.gameStateModel = gameStateModel;
|
||||
}
|
||||
public Image loadBellImage() {
|
||||
Image bell = new Image("ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/game/DayOpen/bell.png");
|
||||
return bell;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
ChatApp.setGameController(this);
|
||||
}
|
||||
/**
|
||||
* Adds an image of a bell on top of button0
|
||||
*/
|
||||
public void noiseDisplay0() {
|
||||
LOGGER.debug("noise0 called");
|
||||
Platform.runLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
noiseImage0.setImage(loadBellImage());
|
||||
} catch (Exception e) {
|
||||
LOGGER.debug(e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an image of a bell on top of button1
|
||||
*/
|
||||
public void noiseDisplay1() {
|
||||
LOGGER.debug("noise1 called");
|
||||
Platform.runLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
noiseImage1.setImage(loadBellImage());
|
||||
} catch (Exception e) {
|
||||
LOGGER.debug(e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an image of a bell on top of button2
|
||||
*/
|
||||
public void noiseDisplay2() {
|
||||
LOGGER.debug("noise2 called");
|
||||
Platform.runLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
noiseImage2.setImage(loadBellImage());
|
||||
} catch (Exception e) {
|
||||
LOGGER.debug(e.getMessage());
|
||||
;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an image of a bell on top of button3
|
||||
*/
|
||||
public void noiseDisplay3() {
|
||||
LOGGER.debug("noise3 called");
|
||||
Platform.runLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
LOGGER.debug("hello");
|
||||
noiseImage3.setImage(loadBellImage());
|
||||
} catch (Exception e) {
|
||||
LOGGER.debug(e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an image of a bell on top of button4
|
||||
*/
|
||||
public void noiseDisplay4() {
|
||||
LOGGER.debug("noise4 called");
|
||||
Platform.runLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
LOGGER.debug("hello");
|
||||
noiseImage4.setImage(loadBellImage());
|
||||
} catch (Exception e) {
|
||||
LOGGER.debug(e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an image of a bell on top of button5
|
||||
*/
|
||||
public void noiseDisplay5() {
|
||||
LOGGER.debug("noise5 called");
|
||||
Platform.runLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
noiseImage5.setImage(loadBellImage());
|
||||
} catch (Exception e) {
|
||||
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(
|
||||
GameStateModel gameStateModel) {
|
||||
GameController.gameStateModel = gameStateModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
ChatApp.setGameController(this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ public class ClientListItem {
|
||||
private final int id;
|
||||
|
||||
private static int uid = 0;
|
||||
|
||||
public ClientListItem(String name, int id) {
|
||||
this.name = new SimpleStringProperty(name);
|
||||
this.id = id;
|
||||
@ -19,7 +20,7 @@ public class ClientListItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
public String toString() {
|
||||
return name + " ID: " + id;
|
||||
}
|
||||
|
||||
|
||||
@ -26,8 +26,7 @@ public class LobbyListItem {
|
||||
private final int MAX_CAPACITY = 6;
|
||||
private SimpleIntegerProperty noOfPlayersInLobby;
|
||||
|
||||
public LobbyListItem(SimpleStringProperty lobbyID,
|
||||
SimpleStringProperty adminName,
|
||||
public LobbyListItem(SimpleStringProperty lobbyID, SimpleStringProperty adminName,
|
||||
SimpleBooleanProperty ownedByClient, SimpleBooleanProperty isOpen,
|
||||
SimpleIntegerProperty noOfPlayersInLobby) {
|
||||
this.lobbyID = lobbyID;
|
||||
@ -66,8 +65,7 @@ public class LobbyListItem {
|
||||
return clientsInLobby;
|
||||
}
|
||||
|
||||
public void setClientsInLobby(
|
||||
ObservableList<SimpleStringProperty> clientsInLobby) {
|
||||
public void setClientsInLobby(ObservableList<SimpleStringProperty> clientsInLobby) {
|
||||
this.clientsInLobby = clientsInLobby;
|
||||
}
|
||||
|
||||
@ -113,14 +111,9 @@ public class LobbyListItem {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LobbyListItem{" +
|
||||
"lobbyID=" + lobbyID +
|
||||
", adminName=" + adminName +
|
||||
", clientsInLobby=" + clientsInLobby +
|
||||
", ownedByClient=" + ownedByClient +
|
||||
", isOpen=" + isOpen +
|
||||
", MAX_CAPACITY=" + MAX_CAPACITY +
|
||||
", noOfPlayersInLobby=" + noOfPlayersInLobby +
|
||||
'}';
|
||||
return "LobbyListItem{" + "lobbyID=" + lobbyID + ", adminName=" + adminName
|
||||
+ ", clientsInLobby=" + clientsInLobby + ", ownedByClient=" + ownedByClient + ", isOpen="
|
||||
+ isOpen + ", MAX_CAPACITY=" + MAX_CAPACITY + ", noOfPlayersInLobby=" + noOfPlayersInLobby
|
||||
+ '}';
|
||||
}
|
||||
}
|
||||
|
||||
@ -339,15 +339,6 @@ public class LoungeSceneViewController implements Initializable {
|
||||
});
|
||||
}
|
||||
|
||||
public void updateClientListView(ObservableList<ClientListItem> names) {
|
||||
ObservableList<ClientListItem> clientsLeft = ClientListView.getItems();
|
||||
clientsLeft.removeAll(names);
|
||||
this.ClientListView.setItems(names);
|
||||
for (ClientListItem gone : clientsLeft) {
|
||||
//TODO
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds players to a lobby
|
||||
* "NMEMB" {@link ch.unibas.dmi.dbis.cs108.multiplayer.helpers.GuiParameters}
|
||||
@ -439,6 +430,20 @@ public class LoungeSceneViewController implements Initializable {
|
||||
|
||||
}
|
||||
|
||||
public void removeClientFromList(String name){
|
||||
Iterator<ClientListItem> it = clients.iterator();
|
||||
while (it.hasNext()) {
|
||||
String uid = it.next().getName();
|
||||
if (uid.equals(name)) {
|
||||
it.remove();
|
||||
break;
|
||||
}
|
||||
} }
|
||||
|
||||
public void removeClientFromLobby(String s){
|
||||
//todo
|
||||
}
|
||||
|
||||
public void newGame() {
|
||||
client.getClient().sendMsgToServer(Protocol.createNewLobby);
|
||||
}
|
||||
@ -457,17 +462,6 @@ public class LoungeSceneViewController implements Initializable {
|
||||
});
|
||||
}
|
||||
|
||||
public void removePlayer(String id) {
|
||||
Iterator<SimpleStringProperty> it = client.getAllClients().iterator();
|
||||
while (it.hasNext()) {
|
||||
String uid = it.next().getValue();
|
||||
if (uid.equals(id)) {
|
||||
it.remove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility to set the client model for this class
|
||||
*
|
||||
|
||||
@ -79,4 +79,10 @@ public class GuiParameters {
|
||||
* Indicates a player has joined the server. Form: {@code NPLOS$<playerName>}
|
||||
*/
|
||||
public static final String newPlayerOnServer = "NPLOS";
|
||||
|
||||
/**
|
||||
* Tells gui to remove a certain player from the list of clients based on user name. Form: {@code
|
||||
* RMVLST$<playerName>}
|
||||
*/
|
||||
public static final String removePlayerFromList = "RMVLST";
|
||||
}
|
||||
|
||||
@ -475,8 +475,9 @@ public class ClientHandler implements Runnable {
|
||||
public void createNewLobby() {
|
||||
if (Lobby.clientIsInLobby(this) == -1) {
|
||||
Lobby newGame = new Lobby(this);
|
||||
guiUpdateAll(Protocol.printToGUI + "$" + GuiParameters.newLobbyCreated + "$" + getLobby()
|
||||
.getLobbyID() + ":" + getClientUserName());
|
||||
guiUpdateAll(
|
||||
Protocol.printToGUI + "$" + GuiParameters.newLobbyCreated + "$" + getLobby().getLobbyID()
|
||||
+ ":" + getClientUserName());
|
||||
LOGGER.debug("Lobby: " + getLobby().getLobbyID() + ". In method createNewLobby()");
|
||||
} else {
|
||||
sendAnnouncementToClient("You are already in lobby nr. " + Lobby.clientIsInLobby(this));
|
||||
|
||||
@ -65,6 +65,7 @@ public class JServerProtocolParser {
|
||||
} catch (Exception e) {
|
||||
h.setUsernameOnLogin("U.N. Owen");
|
||||
}
|
||||
h.guiUpdateAll(Protocol.printToGUI+"$"+GuiParameters.newPlayerOnServer+"$"+h.getClientUserName());
|
||||
break;
|
||||
case Protocol.nameChange:
|
||||
h.changeUsername(msg.substring(6));
|
||||
|
||||
Reference in New Issue
Block a user