made buttons for voting only available when appropriate by chancing their visibility, the client always thinks its a human though, that needs fixing
This commit is contained in:
parent
4079561f7e
commit
4262fb64dd
@ -140,6 +140,7 @@ public class Client {
|
||||
String pos = msg.substring(0, msgIndex);
|
||||
try {
|
||||
position = Integer.parseInt(pos);
|
||||
gameStateModel.setRoleFromPosition(position);
|
||||
} catch (NumberFormatException e) {
|
||||
LOGGER.warn("Position got scrabbled on the way here");
|
||||
}
|
||||
@ -155,6 +156,7 @@ public class Client {
|
||||
|
||||
public void setPosition(int position) {
|
||||
this.position = position;
|
||||
gameStateModel.setRoleFromPosition(position);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -343,11 +345,15 @@ public class Client {
|
||||
switch (parameter) {
|
||||
case GuiParameters.night: //ClientGameInfoHandler;
|
||||
gameStateModel.setDayClone(false);
|
||||
LOGGER.debug("----------------Night, Your role is:" + gameStateModel.getYourRole() + gameStateModel);
|
||||
chatApp.getGameController().setNoiseButtonInvisible();
|
||||
chatApp.getGameController().setVoteButtonVisibilityNight();
|
||||
break;
|
||||
case GuiParameters.day: //ClientGameInfoHandler
|
||||
gameStateModel.setDayClone(true);
|
||||
LOGGER.debug("----------------Day, Your role is:" + gameStateModel.getYourRole()+ gameStateModel);
|
||||
chatApp.getGameController().setNoiseButtonVisible();
|
||||
chatApp.getGameController().setVoteButtonVisibilityDay();
|
||||
break;
|
||||
case GuiParameters.updateGameState:
|
||||
gameStateModel.setGSFromString(data);
|
||||
|
||||
@ -74,6 +74,10 @@ public class ClientModel {
|
||||
|
||||
}
|
||||
|
||||
public int getClientPosition() {
|
||||
return client.getPosition();
|
||||
}
|
||||
|
||||
public void removeClientFromList(String id){
|
||||
Iterator<SimpleStringProperty> it = allClients.iterator();
|
||||
while(it.hasNext()){
|
||||
|
||||
@ -28,7 +28,7 @@ public class GameStateModel {
|
||||
/**
|
||||
* A primitive clone of the passengerTrain in the GameState of the server.
|
||||
* in passengerTrainClone[0] the names of the passengers are stored, in passengerTrainClone[1] the roles
|
||||
* (human/ghost/spectator). The indices of the array correspond with the positions
|
||||
* (h/g/s). The indices of the array correspond with the positions
|
||||
*/
|
||||
private String[][] passengerTrainClone;
|
||||
|
||||
@ -41,8 +41,9 @@ public class GameStateModel {
|
||||
this.nrOfPlayers = 6;
|
||||
passengerTrainClone = new String[2][nrOfPlayers];
|
||||
for(String role : passengerTrainClone[1]) {
|
||||
role = "";
|
||||
role = "h";
|
||||
}
|
||||
yourRole = "h";
|
||||
kickedOff = new boolean[nrOfPlayers];
|
||||
isDayClone = false;
|
||||
}
|
||||
@ -69,9 +70,12 @@ public class GameStateModel {
|
||||
public void setYourRole(String yourRole) {
|
||||
if(yourRole.equals("h") || yourRole.equals("g") || yourRole.equals("s")) {
|
||||
this.yourRole = yourRole;
|
||||
} else {
|
||||
this.yourRole = "h";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getYourRole() {
|
||||
return yourRole;
|
||||
}
|
||||
@ -125,4 +129,18 @@ public class GameStateModel {
|
||||
LOGGER.warn("data has wrong format");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an integer and extracts the string from the passengerTrain[1] string at the index of the integer
|
||||
* @param position the index of the array
|
||||
*/
|
||||
public void setRoleFromPosition(int position) {
|
||||
String role = "h";
|
||||
try {
|
||||
role = passengerTrainClone[1][position];
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("Not an integer between 0-5");
|
||||
}
|
||||
setYourRole(role);
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,6 +131,73 @@ public class GameController implements Initializable {
|
||||
return chatAreaGame;
|
||||
}
|
||||
|
||||
public void setVoteButtonVisibilityDay(){
|
||||
Platform.runLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
LOGGER.debug(buttonRoom0);
|
||||
if (gameStateModel.getYourRole().equals("h")) {
|
||||
try {
|
||||
buttonRoom0.setVisible(true);
|
||||
buttonRoom1.setVisible(true);
|
||||
buttonRoom2.setVisible(true);
|
||||
buttonRoom3.setVisible(true);
|
||||
buttonRoom4.setVisible(true);
|
||||
buttonRoom5.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
} else {
|
||||
try {
|
||||
buttonRoom0.setVisible(false);
|
||||
buttonRoom1.setVisible(false);
|
||||
buttonRoom2.setVisible(false);
|
||||
buttonRoom3.setVisible(false);
|
||||
buttonRoom4.setVisible(false);
|
||||
buttonRoom5.setVisible(false);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setVoteButtonVisibilityNight(){
|
||||
Platform.runLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
LOGGER.debug(buttonRoom0);
|
||||
if (gameStateModel.getYourRole().equals("g")) {
|
||||
try {
|
||||
buttonRoom0.setVisible(true);
|
||||
buttonRoom1.setVisible(true);
|
||||
buttonRoom2.setVisible(true);
|
||||
buttonRoom3.setVisible(true);
|
||||
buttonRoom4.setVisible(true);
|
||||
buttonRoom5.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
} else {
|
||||
try {
|
||||
buttonRoom0.setVisible(false);
|
||||
buttonRoom1.setVisible(false);
|
||||
buttonRoom2.setVisible(false);
|
||||
buttonRoom3.setVisible(false);
|
||||
buttonRoom4.setVisible(false);
|
||||
buttonRoom5.setVisible(false);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* If button 0 is clicked, send the vote message 0 to the server
|
||||
*/
|
||||
|
||||
@ -14,13 +14,13 @@
|
||||
<children>
|
||||
<BorderPane fx:id="LoungeSceneBorderPane" layoutX="860.0" layoutY="440.0" pickOnBounds="false" stylesheets="@boarderPane.css" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<top>
|
||||
<ToolBar fx:id="NTtBToolBar" pickOnBounds="false" prefHeight="77.0" BorderPane.alignment="CENTER">
|
||||
<ToolBar fx:id="NTtBToolBar" pickOnBounds="false" prefHeight="30.0" BorderPane.alignment="CENTER">
|
||||
<items>
|
||||
<Button fx:id="highScoreButton" mnemonicParsing="false" onAction="#sendHIghScore" text="High Score" />
|
||||
<Button fx:id="lobbyPrintButton" mnemonicParsing="false" onAction="#sendLilstle" text="Lobby List" />
|
||||
<Button fx:id="LeaveServerButton" mnemonicParsing="false" text="Leave server" />
|
||||
<Button fx:id="leaveLobbyButton" mnemonicParsing="false" onAction="#leaveLobby" text="Leave Lobby" />
|
||||
<Button fx:id="ChangeNameButton" mnemonicParsing="false" text="Change Name" />
|
||||
<Button fx:id="highScoreButton" mnemonicParsing="false" onAction="#sendHIghScore" pickOnBounds="false" text="High Score" />
|
||||
<Button fx:id="lobbyPrintButton" mnemonicParsing="false" onAction="#sendLilstle" pickOnBounds="false" text="Lobby List" />
|
||||
<Button fx:id="LeaveServerButton" mnemonicParsing="false" pickOnBounds="false" text="Leave server" />
|
||||
<Button fx:id="leaveLobbyButton" mnemonicParsing="false" onAction="#leaveLobby" pickOnBounds="false" text="Leave Lobby" />
|
||||
<Button fx:id="ChangeNameButton" mnemonicParsing="false" pickOnBounds="false" text="Change Name" />
|
||||
</items>
|
||||
</ToolBar>
|
||||
</top>
|
||||
@ -60,6 +60,6 @@
|
||||
<ListView fx:id="LobbyListView" pickOnBounds="false" BorderPane.alignment="CENTER" />
|
||||
</right>
|
||||
</BorderPane>
|
||||
<AnchorPane fx:id="gameDisplayAnchorPane" pickOnBounds="false" />
|
||||
<AnchorPane fx:id="gameDisplayAnchorPane" layoutY="39.0" pickOnBounds="false" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
|
||||
Reference in New Issue
Block a user