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 final Player player;
private PropertyChangeListener cardSelectedChangeListener; private PropertyChangeListener cardSelectedChangeListener;
private PropertyChangeListener cardColorChangeListener;
public CardController(Card card, Player player) { public CardController(Card card, Player player) {
this.card = card; this.card = card;
@ -83,6 +84,17 @@ public class CardController implements Controller {
}; };
card.listeners().addPropertyChangeListener(Card.PROPERTY_SELECTED, cardSelectedChangeListener); 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; return parent;
} }
@ -98,5 +110,6 @@ public class CardController implements Controller {
@Override @Override
public void destroy() { public void destroy() {
card.listeners().removePropertyChangeListener(Card.PROPERTY_SELECTED, cardSelectedChangeListener); 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 playButton = (Button) parent.lookup("#playCardBtn");
final Button drawCardButton = (Button) parent.lookup("#drawCardBtn"); final Button drawCardButton = (Button) parent.lookup("#drawCardBtn");
final Button exitGameButton = (Button) parent.lookup("#exitBtn"); 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); CardController lastPlayedCardController = new CardController(game.getLastPlayedCard(), null);
PlayerController playerController = new PlayerController(gameService.getGame().getPlayerService().getPlayerList().getFirst()); PlayerController playerController = new PlayerController(gameService.getGame().getPlayerService().getPlayerList().getFirst());
@ -48,6 +52,26 @@ public class GameController implements Controller {
controllers.add(playerController); controllers.add(playerController);
controllers.add(enemyController); 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 -> { lastPlayedCardPropertyChangeListener = e -> {
lastPlayedCardPane.getChildren().removeAll(); lastPlayedCardPane.getChildren().removeAll();
try { try {
@ -71,7 +95,14 @@ public class GameController implements Controller {
playButton.setOnAction(e -> { playButton.setOnAction(e -> {
Card cardToPlay = game.getPlayerService().getPlayerList().getFirst().getCurrentCard(); 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) { if(cardToPlay.getPlayer() != null) {
cardToPlay.getPlayer().removeCardFromPlayerDeck(cardToPlay); cardToPlay.getPlayer().removeCardFromPlayerDeck(cardToPlay);
gameService.playCard(cardToPlay); gameService.playCard(cardToPlay);

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

@ -13,12 +13,12 @@
<Cursor fx:constant="HAND" /> <Cursor fx:constant="HAND" />
</cursor> </cursor>
</Button> </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>
<Cursor fx:constant="HAND" /> <Cursor fx:constant="HAND" />
</cursor> </cursor>
</Button> </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>
<Cursor fx:constant="HAND" /> <Cursor fx:constant="HAND" />
</cursor> </cursor>

Loading…
Cancel
Save