Browse Source

add gameService to Controller Constructor

main
fdai7736 11 months ago
parent
commit
2fbfd63b1a
  1. 6
      src/main/java/de/hsfulda/onses/App.java
  2. 10
      src/main/java/de/hsfulda/onses/controllers/AppController.java
  3. 14
      src/main/java/de/hsfulda/onses/controllers/GameController.java
  4. 33
      src/main/resources/de/hsfulda/onses/views/game.fxml

6
src/main/java/de/hsfulda/onses/App.java

@ -1,7 +1,7 @@
package de.hsfulda.onses; package de.hsfulda.onses;
import de.hsfulda.onses.controllers.AppController; import de.hsfulda.onses.controllers.AppController;
import de.hsfulda.onses.models.Game;
import de.hsfulda.onses.services.GameService;
import javafx.application.Application; import javafx.application.Application;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.stage.Stage; import javafx.stage.Stage;
@ -9,9 +9,9 @@ import javafx.stage.Stage;
public class App extends Application { public class App extends Application {
@Override @Override
public void start(Stage stage) throws Exception { public void start(Stage stage) throws Exception {
final AppController appController = new AppController(new Game(), stage);
final AppController appController = new AppController(new GameService(), stage);
stage.setTitle("Onses - Uno Game");
stage.setTitle("Onses - Uno");
stage.setScene(new Scene(appController.render())); stage.setScene(new Scene(appController.render()));
stage.show(); stage.show();
} }

10
src/main/java/de/hsfulda/onses/controllers/AppController.java

@ -2,6 +2,7 @@ package de.hsfulda.onses.controllers;
import de.hsfulda.onses.Main; import de.hsfulda.onses.Main;
import de.hsfulda.onses.models.Game; import de.hsfulda.onses.models.Game;
import de.hsfulda.onses.services.GameService;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Parent; import javafx.scene.Parent;
import javafx.scene.Scene; import javafx.scene.Scene;
@ -13,22 +14,23 @@ import java.util.Objects;
public class AppController implements Controller { public class AppController implements Controller {
private final Game game;
private final GameService gameService;
private final Stage stage; private final Stage stage;
public AppController(Game game, Stage stage) {
this.game = game;
public AppController(GameService gameService, Stage stage) {
this.gameService = gameService;
this.stage = stage; this.stage = stage;
} }
@Override @Override
public Parent render() throws IOException { public Parent render() throws IOException {
GameController gameController = new GameController(game);
GameController gameController = new GameController(gameService);
final Parent parent = FXMLLoader.load(Objects.requireNonNull(Main.class.getResource("views/app.fxml"))); final Parent parent = FXMLLoader.load(Objects.requireNonNull(Main.class.getResource("views/app.fxml")));
Button button = (Button) parent.lookup("#startGameBtn"); Button button = (Button) parent.lookup("#startGameBtn");
button.setOnAction(e -> { button.setOnAction(e -> {
try { try {
stage.setScene(new Scene(gameController.render())); stage.setScene(new Scene(gameController.render()));
stage.setTitle("Onses - Uno Game");
} catch (IOException ex) { } catch (IOException ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }

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

@ -1,21 +1,27 @@
package de.hsfulda.onses.controllers; package de.hsfulda.onses.controllers;
import de.hsfulda.onses.Main; import de.hsfulda.onses.Main;
import de.hsfulda.onses.models.Game;
import de.hsfulda.onses.models.Card;
import de.hsfulda.onses.services.GameService;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Parent; import javafx.scene.Parent;
import javafx.scene.layout.Pane;
import java.io.IOException; import java.io.IOException;
import java.util.Objects; import java.util.Objects;
public class GameController implements Controller { public class GameController implements Controller {
private final Game game;
public GameController(Game game) {
this.game = game;
private final GameService gameService;
public GameController(GameService gameService) {
this.gameService = gameService;
} }
@Override @Override
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")));
CardController lastPlayedCardController = new CardController(new Card().setValue(Card.Value.FIVE).setColor(Card.Color.BLUE));
Pane lastPlayedCardPane = (Pane) parent.lookup("#lastPlayedCardPane");
lastPlayedCardPane.getChildren().add(lastPlayedCardController.render());
return parent; return parent;
} }

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

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.Cursor?>
<?import javafx.scene.control.Button?> <?import javafx.scene.control.Button?>
<?import javafx.scene.layout.AnchorPane?> <?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.Pane?> <?import javafx.scene.layout.Pane?>
@ -8,16 +9,38 @@
<AnchorPane prefHeight="690.0" prefWidth="1254.0" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1"> <AnchorPane prefHeight="690.0" prefWidth="1254.0" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1">
<children> <children>
<Button fx:id="btnWishBlue" layoutX="891.0" layoutY="558.0" mnemonicParsing="false" style="-fx-background-color: blue; -fx-pref-width: 30px; -fx-pref-height: 30px;" AnchorPane.bottomAnchor="100.0" AnchorPane.rightAnchor="280.0" />
<Button fx:id="btnWishRed" layoutX="931.0" layoutY="558.0" mnemonicParsing="false" style="-fx-background-color: red; -fx-pref-width: 30px; -fx-pref-height: 30px; -fx-cursor: pointer;" AnchorPane.bottomAnchor="100.0" AnchorPane.rightAnchor="240.0" />
<Button fx:id="btnWishGreen" layoutX="891.0" layoutY="602.0" mnemonicParsing="false" style="-fx-background-color: green; -fx-pref-width: 30px; -fx-pref-height: 30px; -fx-cursor: pointer;" AnchorPane.bottomAnchor="58.0" AnchorPane.rightAnchor="240.0" />
<Button fx:id="btnWishYellow" layoutX="891.0" layoutY="602.0" mnemonicParsing="false" style="-fx-background-color: yellow; -fx-pref-width: 30px; -fx-pref-height: 30px;" AnchorPane.bottomAnchor="58.0" AnchorPane.rightAnchor="280.0" />
<Button fx:id="btnWishBlue" layoutX="891.0" layoutY="558.0" mnemonicParsing="false" style="-fx-background-color: blue; -fx-pref-width: 30px; -fx-pref-height: 30px;" AnchorPane.bottomAnchor="100.0" AnchorPane.rightAnchor="280.0">
<cursor>
<Cursor fx:constant="HAND" />
</cursor>
</Button>
<Button fx:id="btnWishRed" layoutX="931.0" layoutY="558.0" mnemonicParsing="false" style="-fx-background-color: red; -fx-pref-width: 30px; -fx-pref-height: 30px; -fx-cursor: pointer;" AnchorPane.bottomAnchor="100.0" AnchorPane.rightAnchor="240.0">
<cursor>
<Cursor fx:constant="HAND" />
</cursor>
</Button>
<Button fx:id="btnWishGreen" layoutX="891.0" layoutY="602.0" mnemonicParsing="false" style="-fx-background-color: green; -fx-pref-width: 30px; -fx-pref-height: 30px; -fx-cursor: pointer;" AnchorPane.bottomAnchor="58.0" AnchorPane.rightAnchor="240.0">
<cursor>
<Cursor fx:constant="HAND" />
</cursor>
</Button>
<Button fx:id="btnWishYellow" layoutX="891.0" layoutY="602.0" mnemonicParsing="false" style="-fx-background-color: yellow; -fx-pref-width: 30px; -fx-pref-height: 30px;" AnchorPane.bottomAnchor="58.0" AnchorPane.rightAnchor="280.0">
<cursor>
<Cursor fx:constant="HAND" />
</cursor>
</Button>
<Button layoutX="1085.0" layoutY="586.0" mnemonicParsing="false" text="Play Card"> <Button layoutX="1085.0" layoutY="586.0" mnemonicParsing="false" text="Play Card">
<font> <font>
<Font size="18.0" /> <Font size="18.0" />
</font> </font>
</Button> </Button>
<Pane fx:id="playerPane" layoutX="18.0" layoutY="460.0" prefHeight="217.0" prefWidth="891.0" style="-fx-border-color: red;" AnchorPane.bottomAnchor="13.0" AnchorPane.leftAnchor="18.0" AnchorPane.rightAnchor="345.0" /> <Pane fx:id="playerPane" layoutX="18.0" layoutY="460.0" prefHeight="217.0" prefWidth="891.0" style="-fx-border-color: red;" AnchorPane.bottomAnchor="13.0" AnchorPane.leftAnchor="18.0" AnchorPane.rightAnchor="345.0" />
<Pane layoutX="18.0" layoutY="14.0" prefHeight="217.0" prefWidth="891.0" style="-fx-border-color: red;" />
<Pane fx:id="enemyPane" layoutX="18.0" layoutY="14.0" prefHeight="217.0" prefWidth="891.0" style="-fx-border-color: red;" />
<Pane fx:id="lastPlayedCardPane" layoutX="112.0" layoutY="245.0" maxHeight="-Infinity" maxWidth="-Infinity" prefHeight="200.0" prefWidth="130.0" AnchorPane.leftAnchor="112.0" AnchorPane.topAnchor="245.0" />
<Button layoutX="404.0" layoutY="329.0" mnemonicParsing="false" text="Draw Card" AnchorPane.leftAnchor="404.0" AnchorPane.topAnchor="329.0">
<font>
<Font size="18.0" />
</font>
</Button>
</children> </children>
</AnchorPane> </AnchorPane>
Loading…
Cancel
Save