diff --git a/src/main/java/de/hsfulda/onses/controllers/GameController.java b/src/main/java/de/hsfulda/onses/controllers/GameController.java index 2da4cb3..11ae0ae 100644 --- a/src/main/java/de/hsfulda/onses/controllers/GameController.java +++ b/src/main/java/de/hsfulda/onses/controllers/GameController.java @@ -23,9 +23,13 @@ public class GameController implements Controller { public Parent render() throws IOException { final Parent parent = FXMLLoader.load(Objects.requireNonNull(Main.class.getResource("views/game.fxml"))); final Pane lastPlayedCardPane = (Pane) parent.lookup("#lastPlayedCardPane"); - + final Pane enemyPane = (Pane) parent.lookup("#enemyPane"); + final Pane playerPane = (Pane) parent.lookup("#playerPane"); final Button playButton = (Button) parent.lookup("#playCardBtn"); - CardController lastPlayedCardController = new CardController(new Card().setValue(Card.Value.FIVE).setColor(Card.Color.BLUE)); + + CardController lastPlayedCardController = new CardController(game.getLastPlayedCard()); + 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(); @@ -42,6 +46,8 @@ public class GameController implements Controller { lastPlayedCardPane.getChildren().add(lastPlayedCardController.render()); + playerPane.getChildren().add(playerController.render()); + enemyPane.getChildren().add(enemyController.render()); return parent; } diff --git a/src/main/java/de/hsfulda/onses/controllers/PlayerController.java b/src/main/java/de/hsfulda/onses/controllers/PlayerController.java index 7cdb72f..1757520 100644 --- a/src/main/java/de/hsfulda/onses/controllers/PlayerController.java +++ b/src/main/java/de/hsfulda/onses/controllers/PlayerController.java @@ -1,16 +1,46 @@ 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; +import javafx.scene.layout.HBox; import java.io.IOException; +import java.util.ArrayList; import java.util.Objects; public class PlayerController implements Controller { + + private final Player player; + + public PlayerController(Player player) { + this.player = player; + } @Override public Parent render() throws IOException { final Parent parent = FXMLLoader.load(Objects.requireNonNull(Main.class.getResource("views/player.fxml"))); + final Label playerNameLabel = (Label) parent.lookup("#playerNameLabel"); + final HBox cards = (HBox) parent.lookup("#cardsHBox"); + + for(Card card : player.getPlayerDeck()) { + cards.getChildren().add(new CardController(card).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()); + } catch (IOException ex) { + throw new RuntimeException(ex); + } + } + }); + + playerNameLabel.setText("Test"); return parent; } diff --git a/src/main/java/de/hsfulda/onses/models/Player.java b/src/main/java/de/hsfulda/onses/models/Player.java index 695e3d4..9dbfa14 100644 --- a/src/main/java/de/hsfulda/onses/models/Player.java +++ b/src/main/java/de/hsfulda/onses/models/Player.java @@ -27,6 +27,12 @@ public class Player { this.firePropertyChange(PROPERTY_PLAYER_DECK, oldplayerDeck, playerDeck); } + public void removeCardFromPlayerDeck(Card card) { + final ArrayList oldPlayerDeck = new ArrayList<>(this.playerDeck); + this.playerDeck.remove(card); + this.firePropertyChange(PROPERTY_PLAYER_DECK, oldPlayerDeck, playerDeck); + } + public PlayerService getPlayerService() { return playerService; } diff --git a/src/main/resources/de/hsfulda/onses/views/game.fxml b/src/main/resources/de/hsfulda/onses/views/game.fxml index 5ca0e51..e0e8f23 100644 --- a/src/main/resources/de/hsfulda/onses/views/game.fxml +++ b/src/main/resources/de/hsfulda/onses/views/game.fxml @@ -8,33 +8,33 @@ - - - - - - - + +