Browse Source
Merge branch 'PlayerController' into 'main'
Merge branch 'PlayerController' into 'main'
add basic Player controller See merge request fdai7736/onses!27main
fdai7736
11 months ago
6 changed files with 82 additions and 18 deletions
-
10src/main/java/de/hsfulda/onses/controllers/GameController.java
-
30src/main/java/de/hsfulda/onses/controllers/PlayerController.java
-
6src/main/java/de/hsfulda/onses/models/Player.java
-
14src/main/resources/de/hsfulda/onses/views/game.fxml
-
22src/main/resources/de/hsfulda/onses/views/player.fxml
-
18src/test/java/de/hsfulda/onses/PlayerTest.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; |
|||
} |
|||
|
@ -1,13 +1,17 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
|
|||
<?import java.lang.*?> |
|||
<?import java.util.*?> |
|||
<?import javafx.scene.*?> |
|||
<?import javafx.scene.control.*?> |
|||
<?import javafx.scene.layout.*?> |
|||
|
|||
<AnchorPane xmlns="http://javafx.com/javafx" |
|||
xmlns:fx="http://javafx.com/fxml" |
|||
prefHeight="400.0" prefWidth="600.0"> |
|||
<?import javafx.scene.control.Label?> |
|||
<?import javafx.scene.layout.AnchorPane?> |
|||
<?import javafx.scene.layout.HBox?> |
|||
<?import javafx.scene.text.Font?> |
|||
|
|||
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" prefHeight="228.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="3.0" AnchorPane.topAnchor="1.0"> |
|||
<font> |
|||
<Font size="17.0" /> |
|||
</font> |
|||
</Label> |
|||
<HBox fx:id="cardsHBox" layoutY="22.0" prefHeight="200.0" prefWidth="940.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="3.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="25.0" /> |
|||
</children> |
|||
</AnchorPane> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue