-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainApp.java
More file actions
76 lines (56 loc) · 2.22 KB
/
MainApp.java
File metadata and controls
76 lines (56 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.ImageView;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.image.Image;
import java.io.File;
import java.util.Objects;
public class MainApp extends Application{
public static final int TILE_SIZE = 80;
@Override
public void start(Stage stage) throws Exception {
GridPane grid = new GridPane();
Game.createBoard();
Game.createAndPlacePieces();
for(int row=7; row>=0;row--){
for(int col=0; col<8;col++){
StackPane cell = new StackPane();
cell.setPrefSize(TILE_SIZE, TILE_SIZE);
Tile tile = Game.board[row][col];
tile.setCell(cell);
cell.setUserData(tile);
Color bgColor = (row + col) % 2 == 0 ? Color.BEIGE : Color.SADDLEBROWN;
Rectangle background = new Rectangle(TILE_SIZE, TILE_SIZE, bgColor);
ImageView pieceView = null;
if(tile.getPiece() != null) {
String pieceName = tile.getPiece().getName();
File f = new File("out/production/Chess/pictures/" + pieceName + ".png");
Image pieceImage = new Image(f.toURI().toString());
pieceView = new ImageView(pieceImage);
pieceView.setFitWidth(TILE_SIZE);
pieceView.setFitHeight(TILE_SIZE);
pieceView.setPreserveRatio(true);
tile.getPiece().setImageView(pieceView);
}
cell.getChildren().add(background);
if(pieceView != null){
cell.getChildren().add(pieceView);
}
GameController.makeMove(tile, tile.getCell());
grid.add(cell, col, 7-row);
}
}
Scene scene = new Scene(grid);
stage.setScene(scene);
stage.setTitle("Chess");
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}