From cb4811b339efa1644a21cca173f83f45fd7197a8 Mon Sep 17 00:00:00 2001 From: Debucquoy Date: Sat, 22 Apr 2023 17:08:19 +0200 Subject: [PATCH] First Controller prototype The goal it that for each window "type" there is a subclass of Parrent and we can dynamicly switch between each scene with a fonction This first commit is to see the structure for other to work on it. the goal will be to make it dynamic. at the moment you have to switch the gameState Variable with the window you would like to load. --- .../main/java/school_project/Controller.java | 26 ++++++++++++------- .../java/school_project/States/GameMain.java | 8 ++++++ .../java/school_project/States/GameMenu.java | 12 +++++++++ .../java/school_project/States/GameState.java | 6 +++++ 4 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 app/src/main/java/school_project/States/GameMain.java create mode 100644 app/src/main/java/school_project/States/GameMenu.java create mode 100644 app/src/main/java/school_project/States/GameState.java diff --git a/app/src/main/java/school_project/Controller.java b/app/src/main/java/school_project/Controller.java index c979cac..cf7606e 100644 --- a/app/src/main/java/school_project/Controller.java +++ b/app/src/main/java/school_project/Controller.java @@ -4,25 +4,33 @@ package school_project; import javafx.application.Application; -import javafx.scene.Group; +import javafx.scene.Parent; import javafx.scene.Scene; -import javafx.scene.control.Button; import javafx.stage.Stage; +import school_project.States.GameMain; +import school_project.States.GameMenu; +import school_project.States.GameState; public class Controller extends Application { + public final static String PROGRAM_NAME = "Road to Master"; + private Parent root; + private GameState gameState = GameState.InMenu; @Override public void start(Stage primaryStage) throws Exception { - primaryStage.setTitle("test"); - Button btn = new Button("test"); - btn.setOnAction(event -> System.out.println("hey")); + primaryStage.setTitle(PROGRAM_NAME); - Group root = new Group(); - root.getChildren().add(btn); + switch (gameState){ + case InMenu: + root = new GameMenu(); + break; + case InGame: + root = new GameMain(); + break; + } - Scene scene = new Scene(root, 300,300); + Scene scene = new Scene(root); primaryStage.setScene(scene); - primaryStage.show(); } diff --git a/app/src/main/java/school_project/States/GameMain.java b/app/src/main/java/school_project/States/GameMain.java new file mode 100644 index 0000000..9a8b861 --- /dev/null +++ b/app/src/main/java/school_project/States/GameMain.java @@ -0,0 +1,8 @@ +package school_project.States; + +import javafx.scene.layout.BorderPane; + +public class GameMain extends BorderPane { + + +} diff --git a/app/src/main/java/school_project/States/GameMenu.java b/app/src/main/java/school_project/States/GameMenu.java new file mode 100644 index 0000000..7dee84e --- /dev/null +++ b/app/src/main/java/school_project/States/GameMenu.java @@ -0,0 +1,12 @@ +package school_project.States; + +import javafx.scene.layout.GridPane; +import javafx.scene.text.Text; + +public class GameMenu extends GridPane { + Text txt = new Text("Here come the menu"); + public GameMenu() { + super(); + add(txt, 0, 0); + } +} diff --git a/app/src/main/java/school_project/States/GameState.java b/app/src/main/java/school_project/States/GameState.java new file mode 100644 index 0000000..f267fe9 --- /dev/null +++ b/app/src/main/java/school_project/States/GameState.java @@ -0,0 +1,6 @@ +package school_project.States; + +public enum GameState { + InMenu, + InGame +} -- 2.46.0