Browse Source

fix that wish card works in GUI

main^2
fdai7736 11 months ago
parent
commit
a39735c627
  1. 13
      src/main/java/de/hsfulda/onses/controllers/CardController.java
  2. 33
      src/main/java/de/hsfulda/onses/controllers/GameController.java
  3. 4
      src/main/resources/de/hsfulda/onses/views/game.fxml

13
src/main/java/de/hsfulda/onses/controllers/CardController.java

@ -18,6 +18,7 @@ public class CardController implements Controller {
private final Player player;
private PropertyChangeListener cardSelectedChangeListener;
private PropertyChangeListener cardColorChangeListener;
public CardController(Card card, Player player) {
this.card = card;
@ -83,6 +84,17 @@ public class CardController implements Controller {
};
card.listeners().addPropertyChangeListener(Card.PROPERTY_SELECTED, cardSelectedChangeListener);
cardColorChangeListener = e -> {
switch((Card.Color)e.getNewValue()) {
case RED -> mainPane.setStyle(addStyle(mainPane.getStyle(), "-fx-background-color: red"));
case BLUE -> mainPane.setStyle(addStyle(mainPane.getStyle(), "-fx-background-color: blue"));
case GREEN -> mainPane.setStyle(addStyle(mainPane.getStyle(), "-fx-background-color: green"));
case YELLOW -> mainPane.setStyle(addStyle(mainPane.getStyle(), "-fx-background-color: yellow"));
default -> mainPane.setStyle(addStyle(mainPane.getStyle(), "-fx-background-color: black"));
}
};
card.listeners().addPropertyChangeListener(Card.PROPERTY_COLOR, cardColorChangeListener);
return parent;
}
@ -98,5 +110,6 @@ public class CardController implements Controller {
@Override
public void destroy() {
card.listeners().removePropertyChangeListener(Card.PROPERTY_SELECTED, cardSelectedChangeListener);
card.listeners().removePropertyChangeListener(Card.PROPERTY_COLOR, cardColorChangeListener);
}
}

33
src/main/java/de/hsfulda/onses/controllers/GameController.java

@ -39,6 +39,10 @@ public class GameController implements Controller {
final Button playButton = (Button) parent.lookup("#playCardBtn");
final Button drawCardButton = (Button) parent.lookup("#drawCardBtn");
final Button exitGameButton = (Button) parent.lookup("#exitBtn");
final Button wishRedButton = (Button) parent.lookup("#btnWishRed");
final Button wishBlueButton = (Button) parent.lookup("#btnWishBlue");
final Button wishGreenButton = (Button) parent.lookup("#btnWishGreen");
final Button wishYellowButton = (Button) parent.lookup("#btnWishYellow");
CardController lastPlayedCardController = new CardController(game.getLastPlayedCard(), null);
PlayerController playerController = new PlayerController(gameService.getGame().getPlayerService().getPlayerList().getFirst());
@ -48,6 +52,26 @@ public class GameController implements Controller {
controllers.add(playerController);
controllers.add(enemyController);
wishRedButton.setOnAction(e -> {
Card currentSelectedCard = game.getPlayerService().getPlayerList().getFirst().getCurrentCard();
currentSelectedCard.setColor(Card.Color.RED);
});
wishBlueButton.setOnAction(e -> {
Card currentSelectedCard = game.getPlayerService().getPlayerList().getFirst().getCurrentCard();
currentSelectedCard.setColor(Card.Color.BLUE);
});
wishGreenButton.setOnAction(e -> {
Card currentSelectedCard = game.getPlayerService().getPlayerList().getFirst().getCurrentCard();
currentSelectedCard.setColor(Card.Color.GREEN);
});
wishYellowButton.setOnAction(e -> {
Card currentSelectedCard = game.getPlayerService().getPlayerList().getFirst().getCurrentCard();
currentSelectedCard.setColor(Card.Color.YELLOW);
});
lastPlayedCardPropertyChangeListener = e -> {
lastPlayedCardPane.getChildren().removeAll();
try {
@ -71,7 +95,14 @@ public class GameController implements Controller {
playButton.setOnAction(e -> {
Card cardToPlay = game.getPlayerService().getPlayerList().getFirst().getCurrentCard();
if(gameService.legalMove(cardToPlay)) {
if(cardToPlay.getValue().equals(Card.Value.CHOOSE) || cardToPlay.getValue().equals(Card.Value.CHOOSEDRAW)) {
if(!cardToPlay.getColor().equals(Card.Color.BLACK)) {
if(cardToPlay.getPlayer() != null) {
cardToPlay.getPlayer().removeCardFromPlayerDeck(cardToPlay);
gameService.playCard(cardToPlay);
}
}
} else if(gameService.legalMove(cardToPlay)){
if(cardToPlay.getPlayer() != null) {
cardToPlay.getPlayer().removeCardFromPlayerDeck(cardToPlay);
gameService.playCard(cardToPlay);

4
src/main/resources/de/hsfulda/onses/views/game.fxml

@ -13,12 +13,12 @@
<Cursor fx:constant="HAND" />
</cursor>
</Button>
<Button fx:id="btnWishRed" layoutX="1160.0" layoutY="507.0" mnemonicParsing="false" style="-fx-background-color: red; -fx-pref-width: 30px; -fx-pref-height: 30px; -fx-cursor: pointer;" AnchorPane.bottomAnchor="153.0" AnchorPane.rightAnchor="64.0">
<Button fx:id="btnWishRed" layoutX="1160.0" layoutY="507.0" mnemonicParsing="false" style="-fx-background-color: red; -fx-pref-width: 30px; -fx-pref-height: 30px;" AnchorPane.bottomAnchor="153.0" AnchorPane.rightAnchor="64.0">
<cursor>
<Cursor fx:constant="HAND" />
</cursor>
</Button>
<Button fx:id="btnWishGreen" layoutX="1160.0" layoutY="549.0" mnemonicParsing="false" style="-fx-background-color: green; -fx-pref-width: 30px; -fx-pref-height: 30px; -fx-cursor: pointer;" AnchorPane.bottomAnchor="111.0" AnchorPane.rightAnchor="64.0">
<Button fx:id="btnWishGreen" layoutX="1160.0" layoutY="549.0" mnemonicParsing="false" style="-fx-background-color: green; -fx-pref-width: 30px; -fx-pref-height: 30px;" AnchorPane.bottomAnchor="111.0" AnchorPane.rightAnchor="64.0">
<cursor>
<Cursor fx:constant="HAND" />
</cursor>

Loading…
Cancel
Save