Browse Source

add selected Card player

main^2
fdai7736 11 months ago
parent
commit
f5b7c26cf7
  1. 28
      src/main/java/de/hsfulda/onses/controllers/CardController.java
  2. 4
      src/main/java/de/hsfulda/onses/controllers/GameController.java
  3. 4
      src/main/java/de/hsfulda/onses/controllers/PlayerController.java

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

@ -2,6 +2,7 @@ package de.hsfulda.onses.controllers;
import de.hsfulda.onses.Main;
import de.hsfulda.onses.models.Card;
import de.hsfulda.onses.models.Player;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.control.Label;
@ -12,10 +13,12 @@ import java.util.Objects;
public class CardController implements Controller {
private Card card;
private final Card card;
private final Player player;
public CardController(Card card) {
public CardController(Card card, Player player) {
this.card = card;
this.player = player;
}
@Override
public Parent render() throws IOException {
@ -53,6 +56,27 @@ public class CardController implements Controller {
}
}
if(player != null && !player.isEnemy()) {
mainPane.setOnMousePressed(e -> {
Card oldCard = player.getCurrentCard();
if(oldCard != null) {
oldCard.setSelected(false);
}
player.setCurrentCard(card);
card.setSelected(true);
});
}
card.listeners().addPropertyChangeListener(Card.PROPERTY_SELECTED, e -> {
boolean oldValue = (boolean) e.getOldValue();
if(oldValue) {
mainPane.setStyle(addStyle(mainPane.getStyle(), "-fx-border-color: black"));
} else {
mainPane.setStyle(addStyle(mainPane.getStyle(), "-fx-border-color: pink"));
}
});
return parent;
}

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

@ -27,14 +27,14 @@ public class GameController implements Controller {
final Pane playerPane = (Pane) parent.lookup("#playerPane");
final Button playButton = (Button) parent.lookup("#playCardBtn");
CardController lastPlayedCardController = new CardController(game.getLastPlayedCard());
CardController lastPlayedCardController = new CardController(game.getLastPlayedCard(), null);
PlayerController playerController = new PlayerController(gameService.getGame().getPlayerService().getPlayerList().getFirst());
PlayerController enemyController = new PlayerController(gameService.getGame().getPlayerService().getPlayerList().getLast());
game.listeners().addPropertyChangeListener(Game.PROPERTY_LAST_PLAYED_CARD, e -> {
lastPlayedCardPane.getChildren().removeAll();
try {
lastPlayedCardPane.getChildren().add(new CardController((Card) e.getNewValue()).render());
lastPlayedCardPane.getChildren().add(new CardController((Card) e.getNewValue(), null).render());
} catch (IOException ex) {
throw new RuntimeException(ex);
}

4
src/main/java/de/hsfulda/onses/controllers/PlayerController.java

@ -26,14 +26,14 @@ public class PlayerController implements Controller {
final HBox cards = (HBox) parent.lookup("#cardsHBox");
for(Card card : player.getPlayerDeck()) {
cards.getChildren().add(new CardController(card).render());
cards.getChildren().add(new CardController(card, player).render());
}
player.listeners().addPropertyChangeListener(Player.PROPERTY_PLAYER_DECK, e -> {
cards.getChildren().clear();
for(Card card : player.getPlayerDeck()) {
try {
cards.getChildren().add(new CardController(card).render());
cards.getChildren().add(new CardController(card, player).render());
} catch (IOException ex) {
throw new RuntimeException(ex);
}

Loading…
Cancel
Save