Cleaner code
This commit is contained in:
		@ -4,26 +4,43 @@
 | 
				
			|||||||
package school_project;
 | 
					package school_project;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import javafx.application.Application;
 | 
					import javafx.application.Application;
 | 
				
			||||||
import javafx.scene.Group;
 | 
					import javafx.scene.Parent;
 | 
				
			||||||
import javafx.scene.Scene;
 | 
					import javafx.scene.Scene;
 | 
				
			||||||
import javafx.scene.control.Button;
 | 
					
 | 
				
			||||||
 | 
					import javafx.scene.input.KeyCombination;
 | 
				
			||||||
 | 
					import javafx.stage.Screen;
 | 
				
			||||||
import javafx.stage.Stage;
 | 
					import javafx.stage.Stage;
 | 
				
			||||||
 | 
					import school_project.Parsers.FileParserFactory;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.io.File;
 | 
				
			||||||
 | 
					import java.io.IOException;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class Controller extends Application {
 | 
					public class Controller extends Application {
 | 
				
			||||||
 | 
					    private Stage stage;
 | 
				
			||||||
 | 
					    Parent root;
 | 
				
			||||||
 | 
					    public static Vec2 screen_size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void start(Stage primaryStage) throws Exception {
 | 
					    public void start(Stage primaryStage) throws IOException {
 | 
				
			||||||
        primaryStage.setTitle("test");
 | 
					        stage = primaryStage;
 | 
				
			||||||
        Button btn = new Button("test");
 | 
					        screen_size = new Vec2(
 | 
				
			||||||
        btn.setOnAction(event -> System.out.println("hey"));
 | 
					            (int) Screen.getPrimary().getBounds().getWidth(),
 | 
				
			||||||
 | 
					            (int) Screen.getPrimary().getBounds().getHeight()
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Group root = new Group();
 | 
					        stage.setTitle("ROAD TO MASTER YOU");
 | 
				
			||||||
        root.getChildren().add(btn);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Scene scene = new Scene(root, 300,300);
 | 
					        // Full Screen mode
 | 
				
			||||||
        primaryStage.setScene(scene);
 | 
					        stage.setFullScreen(true);
 | 
				
			||||||
 | 
					        stage.setFullScreenExitHint("");
 | 
				
			||||||
 | 
					        primaryStage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        primaryStage.show();
 | 
					        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();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static void main(String[] args) {
 | 
					    public static void main(String[] args) {
 | 
				
			||||||
 | 
				
			|||||||
@ -1,13 +1,7 @@
 | 
				
			|||||||
package school_project;
 | 
					package school_project;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import javafx.geometry.Insets;
 | 
					 | 
				
			||||||
import javafx.geometry.Pos;
 | 
					 | 
				
			||||||
import javafx.scene.Group;
 | 
					import javafx.scene.Group;
 | 
				
			||||||
import javafx.scene.input.MouseButton;
 | 
					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 school_project.Utils.MatrixShape;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.io.FileNotFoundException;
 | 
					import java.io.FileNotFoundException;
 | 
				
			||||||
@ -19,10 +13,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 +32,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);
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user