This commit is contained in:
parent
456128c904
commit
31314749d2
@ -1,24 +1,28 @@
|
|||||||
package school_project;
|
package school_project;
|
||||||
|
|
||||||
|
import javafx.geometry.Insets;
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
import javafx.scene.layout.BorderPane;
|
import javafx.scene.layout.BorderPane;
|
||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import school_project.Utils.MatrixShape;
|
import school_project.Utils.MatrixShape;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
|
||||||
public class GameUI extends BorderPane {
|
public class GameUI extends BorderPane {
|
||||||
public final static int SEGMENT_SIZE = 50;
|
public final static int SEGMENT_SIZE = 50;
|
||||||
public GameUI(Map level) {
|
public final static int SPACE_SIZE = 5;
|
||||||
|
public GameUI(Map level) throws FileNotFoundException {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
MatrixShape grid = new MatrixShape(level);
|
MatrixShape grid = new MatrixShape(level, true);
|
||||||
grid.setAlignment(Pos.CENTER);
|
grid.setAlignment(Pos.CENTER);
|
||||||
grid.setColor(Color.WHITE);
|
grid.setColor(Color.WHITE);
|
||||||
|
|
||||||
HBox pieces = new HBox();
|
HBox pieces = new HBox();
|
||||||
pieces.setSpacing(10);
|
pieces.setSpacing(10);
|
||||||
for (Piece p : level.getPieces()) {
|
for (Piece p : level.getPieces()) {
|
||||||
MatrixShape _piece = new MatrixShape(p);
|
MatrixShape _piece = new MatrixShape(p, false);
|
||||||
_piece.setColor(p.getColor());
|
_piece.setColor(p.getColor());
|
||||||
pieces.getChildren().add(_piece);
|
pieces.getChildren().add(_piece);
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,31 @@
|
|||||||
package school_project.Utils;
|
package school_project.Utils;
|
||||||
|
|
||||||
|
import javafx.scene.Node;
|
||||||
|
import javafx.scene.image.Image;
|
||||||
|
import javafx.scene.image.ImageView;
|
||||||
import javafx.scene.layout.GridPane;
|
import javafx.scene.layout.GridPane;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.paint.Paint;
|
import javafx.scene.paint.Paint;
|
||||||
import javafx.scene.shape.Rectangle;
|
import javafx.scene.shape.Rectangle;
|
||||||
|
import org.checkerframework.common.reflection.qual.GetClass;
|
||||||
|
import school_project.Controller;
|
||||||
import school_project.GameUI;
|
import school_project.GameUI;
|
||||||
import school_project.Shape;
|
import school_project.Shape;
|
||||||
|
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class MatrixShape extends GridPane {
|
public class MatrixShape extends GridPane {
|
||||||
public MatrixShape(){
|
public MatrixShape(Shape shape, boolean texture) throws FileNotFoundException {
|
||||||
super();
|
|
||||||
}
|
|
||||||
public MatrixShape(Shape shape){
|
|
||||||
super();
|
super();
|
||||||
|
setHgap(GameUI.SPACE_SIZE);
|
||||||
|
setVgap(GameUI.SPACE_SIZE);
|
||||||
boolean[][] shape_matrix = shape.getShape();
|
boolean[][] shape_matrix = shape.getShape();
|
||||||
for (int i = 0; i < shape_matrix.length; i++) {
|
for (int i = 0; i < shape_matrix.length; i++) {
|
||||||
for (int j = 0; j < shape_matrix[i].length; j++) {
|
for (int j = 0; j < shape_matrix[i].length; j++) {
|
||||||
if(shape_matrix[i][j]){
|
if(shape_matrix[i][j]){
|
||||||
Rectangle _cell = new Rectangle(GameUI.SEGMENT_SIZE, GameUI.SEGMENT_SIZE);
|
Node _cell = texture ? new ImageView(new Image(new FileInputStream(Controller.class.getResource("tile.png").getFile()))) : new Rectangle(GameUI.SEGMENT_SIZE, GameUI.SEGMENT_SIZE);
|
||||||
add(_cell, j, i);
|
add(_cell, j, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BIN
app/src/main/resources/school_project/tile.png
Normal file
BIN
app/src/main/resources/school_project/tile.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
Loading…
Reference in New Issue
Block a user