Skip to content
Snippets Groups Projects
Commit 094538f2 authored by LABOUREL Arnaud's avatar LABOUREL Arnaud
Browse files

Changed configuration such that the size of the grid and the dimension of...

Changed configuration such that the size of the grid and the dimension of tiles is defined in the fxml  file.
parent 1d767a80
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,7 @@ import javafx.fxml.FXML;
import main.MainApp;
import view.GridTileCanvas;
public class RootLayoutController {
public class MainPaneController {
@FXML
public GridTileCanvas GridTileCanvas;
......
package main;
import controller.RootLayoutController;
import controller.MainPaneController;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import model.TileGrid;
import model.Tile;
import model.TileGame;
import java.io.IOException;
public class MainApp extends Application {
private Stage primaryStage;
private BorderPane rootLayout;
private AnchorPane rootLayout;
private TileGame tileGame = new TileGame();
......@@ -35,7 +33,7 @@ public class MainApp extends Application {
public void initRootLayout() {
try {
// Load root layout from fxml file.
FXMLLoader loader = new FXMLLoader(getClass().getResource("/view/RootLayout.fxml"));
FXMLLoader loader = new FXMLLoader(getClass().getResource("/view/GridCanvas.fxml"));
rootLayout = loader.load();
// Show the scene containing the root layout.
......@@ -43,7 +41,7 @@ public class MainApp extends Application {
primaryStage.setScene(scene);
// Give the controller access to the main app.
RootLayoutController controller = loader.getController();
MainPaneController controller = loader.getController();
controller.setMainApp(this);
primaryStage.show();
......
package view;
import javafx.beans.NamedArg;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
......@@ -10,15 +11,23 @@ import java.util.List;
import java.util.Random;
public class GridTileCanvas extends Canvas {
private static final double TILE_WIDTH = 50;
private static final double TILE_HEIGHT = 50;
private static final int NUMBER_OF_ROWS = 20;
private static final int NUMBER_OF_COLUMNS = 20;
public GridTileCanvas() {
this.setWidth(TILE_WIDTH * NUMBER_OF_COLUMNS);
this.setHeight(TILE_HEIGHT * NUMBER_OF_ROWS);
TileGrid tileGrid = new TileGrid(NUMBER_OF_ROWS, NUMBER_OF_COLUMNS);
public final double tileWidth;
private final double tileHeight;
private final Integer numberOfColumns;
private final Integer numberOfRows;
public GridTileCanvas(@NamedArg("tileWidth") Double tileWidth,
@NamedArg("tileHeight") Double tileHeight,
@NamedArg("numberOfColumns") Integer numberOfColumns,
@NamedArg("numberOfRows") Integer numberOfRows) {
this.tileWidth = tileWidth;
this.tileHeight = tileHeight;
this.numberOfColumns = numberOfColumns;
this.numberOfRows = numberOfRows;
this.setWidth(tileWidth * numberOfColumns);
this.setHeight(tileHeight * numberOfRows);
TileGrid tileGrid = new TileGrid(numberOfRows, numberOfColumns);
tileGrid.fillWithRandomTiles(List.of(Color.BLUE, Color.GREEN, Color.BLACK, Color.RED), new Random());
drawGridTile(tileGrid);
}
......@@ -37,10 +46,10 @@ public class GridTileCanvas extends Canvas {
}
private double getXPosition(int column, PointType pointType){
return (column + pointType.getXPosition()) * TILE_WIDTH;
return (column + pointType.getXPosition()) * tileWidth;
}
private double getYPosition(int row, PointType pointType){
return (row + pointType.getYPosition()) * TILE_HEIGHT;
return (row + pointType.getYPosition()) * tileHeight;
}
private void drawTriangle(int row, int column, CardinalDirection side, Color color){
......
......@@ -4,15 +4,26 @@
<?import view.GridTileCanvas?>
<BorderPane prefHeight="900.0"
prefWidth="900.0"
stylesheets="@DarkTheme.css"
<?import java.lang.Double?>
<?import java.lang.Integer?>
<AnchorPane stylesheets="@DarkTheme.css"
xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="controller.RootLayoutController">
fx:controller="controller.MainPaneController">
<GridTileCanvas xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:id="GridTileCanvas"
height="1000.0" width="1000.0">
fx:id="GridTileCanvas">
<tileHeight>
<Double fx:value="5"/>
</tileHeight>
<tileWidth>
<Double fx:value="5"/>
</tileWidth>
<numberOfColumns>
<Integer fx:value="100"/>
</numberOfColumns>
<numberOfRows>
<Integer fx:value="100"/>
</numberOfRows>
</GridTileCanvas>
</BorderPane>
\ No newline at end of file
</AnchorPane>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment