From ef0ddae0112a4bbb6353469593e3aeb222f54f66 Mon Sep 17 00:00:00 2001 From: Anthony Debucquoy Date: Thu, 4 May 2023 23:24:18 +0200 Subject: [PATCH] Cleaner code --- .../main/java/school_project/Controller.java | 48 ++++++++++--------- app/src/main/java/school_project/GameUI.java | 18 +++---- 2 files changed, 32 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/school_project/Controller.java b/app/src/main/java/school_project/Controller.java index cfa008e..ec69a7f 100644 --- a/app/src/main/java/school_project/Controller.java +++ b/app/src/main/java/school_project/Controller.java @@ -1,39 +1,43 @@ package school_project; import javafx.application.Application; -import javafx.geometry.HPos; -import javafx.geometry.Insets; -import javafx.geometry.Pos; import javafx.scene.Parent; import javafx.scene.Scene; -import javafx.scene.control.Button; -import javafx.scene.control.Label; -import javafx.scene.control.Menu; -import javafx.scene.layout.BorderPane; -import javafx.scene.layout.ColumnConstraints; -import javafx.scene.layout.GridPane; -import javafx.scene.paint.Color; -import javafx.scene.text.Font; +import javafx.scene.input.KeyCombination; +import javafx.stage.Screen; import javafx.stage.Stage; -import school_project.Menu.MenuAcceuil; -import school_project.Menu.MenuLevelDay1; -import school_project.Menu.MenuLevelDay2; +import school_project.Parsers.FileParserFactory; + +import java.io.File; +import java.io.IOException; public class Controller extends Application { private Stage stage; Parent root; + public static Vec2 screen_size; - public void start(Stage primaryStage) { - //set up the page - root = new MenuAcceuil(); + public void start(Stage primaryStage) throws IOException { stage = primaryStage; - stage.setTitle("ROAD TO MASTER YOU"); - stage.setScene(new Scene(root)); - stage.show(); + screen_size = new Vec2( + (int) Screen.getPrimary().getBounds().getWidth(), + (int) Screen.getPrimary().getBounds().getHeight() + ); + stage.setTitle("ROAD TO MASTER YOU"); + + // Full Screen mode + stage.setFullScreen(true); + stage.setFullScreenExitHint(""); + primaryStage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH); + + root = new GameUI(FileParserFactory.loadMapFromFile(new File(getClass().getResource("level11.level").getFile()))); + + Scene scene = new Scene(root, screen_size.x, screen_size.y); + stage.setScene(scene); + stage.show(); } @@ -44,6 +48,4 @@ public class Controller extends Application { public static void main(String[] args) { launch(args); } -} - - +} \ No newline at end of file diff --git a/app/src/main/java/school_project/GameUI.java b/app/src/main/java/school_project/GameUI.java index 84cd28a..9de6550 100644 --- a/app/src/main/java/school_project/GameUI.java +++ b/app/src/main/java/school_project/GameUI.java @@ -1,13 +1,7 @@ package school_project; -import javafx.geometry.Insets; -import javafx.geometry.Pos; import javafx.scene.Group; import javafx.scene.input.MouseButton; -import javafx.scene.layout.BorderPane; -import javafx.scene.layout.HBox; -import javafx.scene.paint.Color; -import javafx.stage.Screen; import school_project.Utils.MatrixShape; import java.io.FileNotFoundException; @@ -19,10 +13,13 @@ public class GameUI extends Group{ super(); MatrixShape grid = new MatrixShape(level); - grid.setLayoutX(Screen.getPrimary().getBounds().getWidth()/2 - grid.boundary_size.x/2); - grid.setLayoutY(Screen.getPrimary().getBounds().getHeight()/2 - grid.boundary_size.y/2); - Group pieces = new Group(); + //center the grid + grid.setLayoutX((Controller.screen_size.x - grid.boundary_size.x) >> 1); + grid.setLayoutY((Controller.screen_size.y - grid.boundary_size.y) >> 1); + + getChildren().add(grid); + for (Piece p : level.getPieces()) { MatrixShape _piece = new MatrixShape(p); _piece.setOnMouseClicked(event -> { @@ -35,9 +32,8 @@ public class GameUI extends Group{ _piece.setLayoutX(event.getSceneX()); _piece.setLayoutY(event.getSceneY()); }); - pieces.getChildren().add(_piece); + getChildren().add(_piece); } - getChildren().addAll(grid, pieces); } }