Cleaner code
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing

This commit is contained in:
Debucquoy Anthony 2023-05-04 23:24:18 +02:00
parent 507437298b
commit a6e62a5303
Signed by: tonitch
GPG Key ID: A78D6421F083D42E
2 changed files with 32 additions and 28 deletions

View File

@ -1,39 +1,43 @@
package school_project; package school_project;
import javafx.application.Application; import javafx.application.Application;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Parent; import javafx.scene.Parent;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Menu; import javafx.scene.input.KeyCombination;
import javafx.scene.layout.BorderPane; import javafx.stage.Screen;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.stage.Stage; import javafx.stage.Stage;
import school_project.Menu.MenuAcceuil; import school_project.Parsers.FileParserFactory;
import school_project.Menu.MenuLevelDay1;
import school_project.Menu.MenuLevelDay2; import java.io.File;
import java.io.IOException;
public class Controller extends Application { public class Controller extends Application {
private Stage stage; private Stage stage;
Parent root; Parent root;
public static Vec2 screen_size;
public void start(Stage primaryStage) { public void start(Stage primaryStage) throws IOException {
//set up the page
root = new MenuAcceuil();
stage = primaryStage; stage = primaryStage;
stage.setTitle("ROAD TO MASTER YOU"); screen_size = new Vec2(
stage.setScene(new Scene(root)); (int) Screen.getPrimary().getBounds().getWidth(),
stage.show(); (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();
} }
@ -45,5 +49,3 @@ public class Controller extends Application {
launch(args); launch(args);
} }
} }

View File

@ -19,10 +19,13 @@ public class GameUI extends Group{
super(); super();
MatrixShape grid = new MatrixShape(level); 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()) { for (Piece p : level.getPieces()) {
MatrixShape _piece = new MatrixShape(p); MatrixShape _piece = new MatrixShape(p);
_piece.setOnMouseClicked(event -> { _piece.setOnMouseClicked(event -> {
@ -35,9 +38,8 @@ public class GameUI extends Group{
_piece.setLayoutX(event.getSceneX()); _piece.setLayoutX(event.getSceneX());
_piece.setLayoutY(event.getSceneY()); _piece.setLayoutY(event.getSceneY());
}); });
pieces.getChildren().add(_piece); getChildren().add(_piece);
} }
getChildren().addAll(grid, pieces);
} }
} }