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);
|
String pos = msg.substring(0, msgIndex);
|
||||||
try {
|
try {
|
||||||
position = Integer.parseInt(pos);
|
position = Integer.parseInt(pos);
|
||||||
|
gameStateModel.setRoleFromPosition(position);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
LOGGER.warn("Position got scrabbled on the way here");
|
LOGGER.warn("Position got scrabbled on the way here");
|
||||||
}
|
}
|
||||||
@ -155,6 +156,7 @@ public class Client {
|
|||||||
|
|
||||||
public void setPosition(int position) {
|
public void setPosition(int position) {
|
||||||
this.position = position;
|
this.position = position;
|
||||||
|
gameStateModel.setRoleFromPosition(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -343,11 +345,15 @@ public class Client {
|
|||||||
switch (parameter) {
|
switch (parameter) {
|
||||||
case GuiParameters.night: //ClientGameInfoHandler;
|
case GuiParameters.night: //ClientGameInfoHandler;
|
||||||
gameStateModel.setDayClone(false);
|
gameStateModel.setDayClone(false);
|
||||||
|
LOGGER.debug("----------------Night, Your role is:" + gameStateModel.getYourRole() + gameStateModel);
|
||||||
chatApp.getGameController().setNoiseButtonInvisible();
|
chatApp.getGameController().setNoiseButtonInvisible();
|
||||||
|
chatApp.getGameController().setVoteButtonVisibilityNight();
|
||||||
break;
|
break;
|
||||||
case GuiParameters.day: //ClientGameInfoHandler
|
case GuiParameters.day: //ClientGameInfoHandler
|
||||||
gameStateModel.setDayClone(true);
|
gameStateModel.setDayClone(true);
|
||||||
|
LOGGER.debug("----------------Day, Your role is:" + gameStateModel.getYourRole()+ gameStateModel);
|
||||||
chatApp.getGameController().setNoiseButtonVisible();
|
chatApp.getGameController().setNoiseButtonVisible();
|
||||||
|
chatApp.getGameController().setVoteButtonVisibilityDay();
|
||||||
break;
|
break;
|
||||||
case GuiParameters.updateGameState:
|
case GuiParameters.updateGameState:
|
||||||
gameStateModel.setGSFromString(data);
|
gameStateModel.setGSFromString(data);
|
||||||
|
|||||||
@ -74,6 +74,10 @@ public class ClientModel {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getClientPosition() {
|
||||||
|
return client.getPosition();
|
||||||
|
}
|
||||||
|
|
||||||
public void removeClientFromList(String id){
|
public void removeClientFromList(String id){
|
||||||
Iterator<SimpleStringProperty> it = allClients.iterator();
|
Iterator<SimpleStringProperty> it = allClients.iterator();
|
||||||
while(it.hasNext()){
|
while(it.hasNext()){
|
||||||
|
|||||||
@ -28,7 +28,7 @@ public class GameStateModel {
|
|||||||
/**
|
/**
|
||||||
* A primitive clone of the passengerTrain in the GameState of the server.
|
* 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
|
* 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;
|
private String[][] passengerTrainClone;
|
||||||
|
|
||||||
@ -41,8 +41,9 @@ public class GameStateModel {
|
|||||||
this.nrOfPlayers = 6;
|
this.nrOfPlayers = 6;
|
||||||
passengerTrainClone = new String[2][nrOfPlayers];
|
passengerTrainClone = new String[2][nrOfPlayers];
|
||||||
for(String role : passengerTrainClone[1]) {
|
for(String role : passengerTrainClone[1]) {
|
||||||
role = "";
|
role = "h";
|
||||||
}
|
}
|
||||||
|
yourRole = "h";
|
||||||
kickedOff = new boolean[nrOfPlayers];
|
kickedOff = new boolean[nrOfPlayers];
|
||||||
isDayClone = false;
|
isDayClone = false;
|
||||||
}
|
}
|
||||||
@ -69,9 +70,12 @@ public class GameStateModel {
|
|||||||
public void setYourRole(String yourRole) {
|
public void setYourRole(String yourRole) {
|
||||||
if(yourRole.equals("h") || yourRole.equals("g") || yourRole.equals("s")) {
|
if(yourRole.equals("h") || yourRole.equals("g") || yourRole.equals("s")) {
|
||||||
this.yourRole = yourRole;
|
this.yourRole = yourRole;
|
||||||
|
} else {
|
||||||
|
this.yourRole = "h";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getYourRole() {
|
public String getYourRole() {
|
||||||
return yourRole;
|
return yourRole;
|
||||||
}
|
}
|
||||||
@ -125,4 +129,18 @@ public class GameStateModel {
|
|||||||
LOGGER.warn("data has wrong format");
|
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;
|
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
|
* If button 0 is clicked, send the vote message 0 to the server
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -14,13 +14,13 @@
|
|||||||
<children>
|
<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">
|
<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>
|
<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>
|
<items>
|
||||||
<Button fx:id="highScoreButton" mnemonicParsing="false" onAction="#sendHIghScore" text="High Score" />
|
<Button fx:id="highScoreButton" mnemonicParsing="false" onAction="#sendHIghScore" pickOnBounds="false" text="High Score" />
|
||||||
<Button fx:id="lobbyPrintButton" mnemonicParsing="false" onAction="#sendLilstle" text="Lobby List" />
|
<Button fx:id="lobbyPrintButton" mnemonicParsing="false" onAction="#sendLilstle" pickOnBounds="false" text="Lobby List" />
|
||||||
<Button fx:id="LeaveServerButton" mnemonicParsing="false" text="Leave server" />
|
<Button fx:id="LeaveServerButton" mnemonicParsing="false" pickOnBounds="false" text="Leave server" />
|
||||||
<Button fx:id="leaveLobbyButton" mnemonicParsing="false" onAction="#leaveLobby" text="Leave Lobby" />
|
<Button fx:id="leaveLobbyButton" mnemonicParsing="false" onAction="#leaveLobby" pickOnBounds="false" text="Leave Lobby" />
|
||||||
<Button fx:id="ChangeNameButton" mnemonicParsing="false" text="Change Name" />
|
<Button fx:id="ChangeNameButton" mnemonicParsing="false" pickOnBounds="false" text="Change Name" />
|
||||||
</items>
|
</items>
|
||||||
</ToolBar>
|
</ToolBar>
|
||||||
</top>
|
</top>
|
||||||
@ -60,6 +60,6 @@
|
|||||||
<ListView fx:id="LobbyListView" pickOnBounds="false" BorderPane.alignment="CENTER" />
|
<ListView fx:id="LobbyListView" pickOnBounds="false" BorderPane.alignment="CENTER" />
|
||||||
</right>
|
</right>
|
||||||
</BorderPane>
|
</BorderPane>
|
||||||
<AnchorPane fx:id="gameDisplayAnchorPane" pickOnBounds="false" />
|
<AnchorPane fx:id="gameDisplayAnchorPane" layoutY="39.0" pickOnBounds="false" />
|
||||||
</children>
|
</children>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
|
|||||||
Reference in New Issue
Block a user