Browse Source

add PlayerController to Game gui for each player

main
fdai7736 11 months ago
parent
commit
a1105e287b
  1. 8
      src/main/java/de/hsfulda/onses/controllers/GameController.java
  2. 21
      src/main/resources/de/hsfulda/onses/views/player.fxml

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

@ -23,9 +23,13 @@ public class GameController implements Controller {
public Parent render() throws IOException { public Parent render() throws IOException {
final Parent parent = FXMLLoader.load(Objects.requireNonNull(Main.class.getResource("views/game.fxml"))); final Parent parent = FXMLLoader.load(Objects.requireNonNull(Main.class.getResource("views/game.fxml")));
final Pane lastPlayedCardPane = (Pane) parent.lookup("#lastPlayedCardPane"); 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"); 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(new Card().setValue(Card.Value.FIVE).setColor(Card.Color.BLUE));
PlayerController playerController = new PlayerController();
PlayerController enemyController = new PlayerController();
game.listeners().addPropertyChangeListener(Game.PROPERTY_LAST_PLAYED_CARD, e -> { game.listeners().addPropertyChangeListener(Game.PROPERTY_LAST_PLAYED_CARD, e -> {
lastPlayedCardPane.getChildren().removeAll(); lastPlayedCardPane.getChildren().removeAll();
@ -42,6 +46,8 @@ public class GameController implements Controller {
lastPlayedCardPane.getChildren().add(lastPlayedCardController.render()); lastPlayedCardPane.getChildren().add(lastPlayedCardController.render());
playerPane.getChildren().add(playerController.render());
enemyPane.getChildren().add(enemyController.render());
return parent; return parent;
} }

21
src/main/resources/de/hsfulda/onses/views/player.fxml

@ -1,13 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.text.Font?>
<AnchorPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
prefHeight="400.0" prefWidth="600.0">
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" prefHeight="220.0" prefWidth="950.0" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label fx:id="playerNameLabel" layoutX="14.0" layoutY="14.0" text="Player Name" AnchorPane.leftAnchor="7.0" AnchorPane.topAnchor="7.0">
<font>
<Font size="17.0" />
</font>
</Label>
<Pane fx:id="cardsPane" layoutX="16.0" layoutY="28.0" prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="5.0" AnchorPane.leftAnchor="7.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="28.0" />
</children>
</AnchorPane> </AnchorPane>
Loading…
Cancel
Save