Cleaner code
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user