5 files + 45 − 27 Inline Compare changes Side-by-side Inline Show whitespace changes Files 5 src/main/java/app/SimulatorApplication.java +3 −3 Original line number Diff line number Diff line Loading @@ -15,8 +15,8 @@ public class SimulatorApplication extends javafx.application.Application { private static final String APP_NAME = "Firefighter simulator"; private static final int ROW_COUNT = 20; private static final int COLUMN_COUNT = 20; private static final int SQUARE_WIDTH = 50; private static final int SQUARE_HEIGHT = 50; private static final int BOX_WIDTH = 50; private static final int BOX_HEIGHT = 50; public static final int INITIAL_FIRE_COUNT = 3; public static final int INITIAL_FIREFIGHTER_COUNT = 6; Loading @@ -43,7 +43,7 @@ public class SimulatorApplication extends javafx.application.Application { loader.setLocation(location); view = loader.load(); Controller controller = loader.getController(); controller.initialize(SQUARE_WIDTH, SQUARE_HEIGHT, COLUMN_COUNT, ROW_COUNT, controller.initialize(BOX_WIDTH, BOX_HEIGHT, COLUMN_COUNT, ROW_COUNT, INITIAL_FIRE_COUNT, INITIAL_FIREFIGHTER_COUNT); } Loading src/main/java/model/FirefighterBoard.java +11 −11 Original line number Diff line number Diff line Loading @@ -58,23 +58,23 @@ public class FirefighterBoard implements Board<List<ModelElement>> { } public List<Position> updateToNextGeneration() { List<Position> result = updateFirefighters(); result.addAll(updateFires()); List<Position> modifiedPositions = updateFirefighters(); modifiedPositions.addAll(updateFires()); step++; return result; return modifiedPositions; } private List<Position> updateFires() { List<Position> result = new ArrayList<>(); List<Position> modifiedPositions = new ArrayList<>(); if (step % 2 == 0) { List<Position> newFirePositions = new ArrayList<>(); for (Position fire : firePositions) { newFirePositions.addAll(neighbors(fire)); } firePositions.addAll(newFirePositions); result.addAll(newFirePositions); modifiedPositions.addAll(newFirePositions); } return result; return modifiedPositions; } Loading @@ -84,22 +84,22 @@ public class FirefighterBoard implements Board<List<ModelElement>> { } private List<Position> updateFirefighters() { List<Position> result = new ArrayList<>(); List<Position> modifiedPosition = new ArrayList<>(); List<Position> firefighterNewPositions = new ArrayList<>(); for (Position firefighterPosition : firefighterPositions) { Position newFirefighterPosition = neighborClosestToFire(firefighterPosition); firefighterNewPositions.add(newFirefighterPosition); extinguish(newFirefighterPosition); result.add(firefighterPosition); result.add(newFirefighterPosition); modifiedPosition.add(firefighterPosition); modifiedPosition.add(newFirefighterPosition); List<Position> neighborFirePositions = neighbors(newFirefighterPosition).stream() .filter(firePositions::contains).toList(); for(Position firePosition : neighborFirePositions) extinguish(firePosition); result.addAll(neighborFirePositions); modifiedPosition.addAll(neighborFirePositions); } firefighterPositions = firefighterNewPositions; return result; return modifiedPosition; } @Override Loading src/main/java/view/FirefighterGrid.java +29 −10 Original line number Diff line number Diff line Loading @@ -10,19 +10,27 @@ import java.util.List; public class FirefighterGrid extends Canvas implements Grid<ViewElement>{ private void paintElementAtPosition(ViewElement element, Position position) { paintSquare(position.row(), position.column(), element.color); paintBox(position.row(), position.column(), element.color); } private int squareWidth; private int squareHeight; private int boxWidth; private int boxHeight; private int columnCount; private int rowCount; @Override public void repaint(List<Pair<Position, ViewElement>> positionedElements) { clear(positionedElements); paint(positionedElements); paintLines(); } private void clear(List<Pair<Position, ViewElement>> positionedElements) { for (Pair<Position, ViewElement> positionElement : positionedElements) { Position position = positionElement.getKey(); clearBox(position.row(), position.column()); } } private void paint(List<Pair<Position, ViewElement>> positionedElements) { for(Pair<Position, ViewElement> pair : positionedElements){ paintElementAtPosition(pair.getValue(), pair.getKey()); Loading @@ -31,10 +39,15 @@ public class FirefighterGrid extends Canvas implements Grid<ViewElement>{ @Override public void repaint(ViewElement[][] elements) { clear(); paint(elements); paintLines(); } private void clear() { getGraphicsContext2D().clearRect(0,0,getWidth(), getHeight()); } private void paint(ViewElement[][] elements) { for(int column = 0; column < columnCount; column++) for(int row = 0; row < rowCount; row++){ Loading @@ -51,11 +64,13 @@ public class FirefighterGrid extends Canvas implements Grid<ViewElement>{ } @Override public void setDimensions(int columnCount, int rowCount, int squareWidth, int squareHeight) { this.squareWidth = squareWidth; this.squareHeight = squareHeight; public void setDimensions(int columnCount, int rowCount, int boxWidth, int boxHeight) { this.boxWidth = boxWidth; this.boxHeight = boxHeight; this.columnCount = columnCount; this.rowCount = rowCount; super.setWidth(boxWidth * columnCount); super.setHeight(boxHeight * rowCount); } private void paintLines(){ Loading @@ -65,16 +80,20 @@ public class FirefighterGrid extends Canvas implements Grid<ViewElement>{ private void paintVerticalLines() { for(int column = 0; column < columnCount; column++) getGraphicsContext2D().strokeLine(column*squareWidth, 0,column*squareWidth, getHeight()); getGraphicsContext2D().strokeLine(column * boxWidth, 0,column * boxWidth, getHeight()); } private void paintHorizontalLines() { for(int row = 0; row < rowCount; row++) getGraphicsContext2D().strokeLine(0, row*squareHeight, getWidth(), row*squareHeight); getGraphicsContext2D().strokeLine(0, row * boxHeight, getWidth(), row * boxHeight); } private void paintSquare(int row, int column, Color color){ private void paintBox(int row, int column, Color color){ getGraphicsContext2D().setFill(color); getGraphicsContext2D().fillRect(row*squareHeight,column*squareWidth,squareHeight,squareWidth); getGraphicsContext2D().fillRect(column * boxWidth,row * boxHeight, boxWidth, boxHeight); } private void clearBox(int row, int column){ getGraphicsContext2D().clearRect(column * boxWidth,row * boxHeight, boxWidth, boxHeight); } } No newline at end of file src/main/java/view/Grid.java +1 −2 Original line number Diff line number Diff line Loading @@ -28,8 +28,7 @@ public interface Grid<E> { void repaint(E[][] elements); /** * Set the dimensions of the grid to the specified column count, row count, square width, and square height. * This method adjusts the dimensions of the grid to the given number of columns, number of rows, square width, * Set the dimensions of the grid to the specified number of columns, number of rows, square width, * and square height. * * @param columnCount The new number of columns in the grid. Loading src/main/resources/view/view.fxml +1 −1 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ mnemonicParsing="false" onAction="#pauseToggleButtonAction" prefHeight="24.0" prefWidth="200.0" styleClass="button" text="Pause"/> </VBox> <FirefighterGrid fx:id="grid" width="1000.0" height="1000.0" <FirefighterGrid fx:id="grid" xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml"> </FirefighterGrid> Loading
src/main/java/app/SimulatorApplication.java +3 −3 Original line number Diff line number Diff line Loading @@ -15,8 +15,8 @@ public class SimulatorApplication extends javafx.application.Application { private static final String APP_NAME = "Firefighter simulator"; private static final int ROW_COUNT = 20; private static final int COLUMN_COUNT = 20; private static final int SQUARE_WIDTH = 50; private static final int SQUARE_HEIGHT = 50; private static final int BOX_WIDTH = 50; private static final int BOX_HEIGHT = 50; public static final int INITIAL_FIRE_COUNT = 3; public static final int INITIAL_FIREFIGHTER_COUNT = 6; Loading @@ -43,7 +43,7 @@ public class SimulatorApplication extends javafx.application.Application { loader.setLocation(location); view = loader.load(); Controller controller = loader.getController(); controller.initialize(SQUARE_WIDTH, SQUARE_HEIGHT, COLUMN_COUNT, ROW_COUNT, controller.initialize(BOX_WIDTH, BOX_HEIGHT, COLUMN_COUNT, ROW_COUNT, INITIAL_FIRE_COUNT, INITIAL_FIREFIGHTER_COUNT); } Loading
src/main/java/model/FirefighterBoard.java +11 −11 Original line number Diff line number Diff line Loading @@ -58,23 +58,23 @@ public class FirefighterBoard implements Board<List<ModelElement>> { } public List<Position> updateToNextGeneration() { List<Position> result = updateFirefighters(); result.addAll(updateFires()); List<Position> modifiedPositions = updateFirefighters(); modifiedPositions.addAll(updateFires()); step++; return result; return modifiedPositions; } private List<Position> updateFires() { List<Position> result = new ArrayList<>(); List<Position> modifiedPositions = new ArrayList<>(); if (step % 2 == 0) { List<Position> newFirePositions = new ArrayList<>(); for (Position fire : firePositions) { newFirePositions.addAll(neighbors(fire)); } firePositions.addAll(newFirePositions); result.addAll(newFirePositions); modifiedPositions.addAll(newFirePositions); } return result; return modifiedPositions; } Loading @@ -84,22 +84,22 @@ public class FirefighterBoard implements Board<List<ModelElement>> { } private List<Position> updateFirefighters() { List<Position> result = new ArrayList<>(); List<Position> modifiedPosition = new ArrayList<>(); List<Position> firefighterNewPositions = new ArrayList<>(); for (Position firefighterPosition : firefighterPositions) { Position newFirefighterPosition = neighborClosestToFire(firefighterPosition); firefighterNewPositions.add(newFirefighterPosition); extinguish(newFirefighterPosition); result.add(firefighterPosition); result.add(newFirefighterPosition); modifiedPosition.add(firefighterPosition); modifiedPosition.add(newFirefighterPosition); List<Position> neighborFirePositions = neighbors(newFirefighterPosition).stream() .filter(firePositions::contains).toList(); for(Position firePosition : neighborFirePositions) extinguish(firePosition); result.addAll(neighborFirePositions); modifiedPosition.addAll(neighborFirePositions); } firefighterPositions = firefighterNewPositions; return result; return modifiedPosition; } @Override Loading
src/main/java/view/FirefighterGrid.java +29 −10 Original line number Diff line number Diff line Loading @@ -10,19 +10,27 @@ import java.util.List; public class FirefighterGrid extends Canvas implements Grid<ViewElement>{ private void paintElementAtPosition(ViewElement element, Position position) { paintSquare(position.row(), position.column(), element.color); paintBox(position.row(), position.column(), element.color); } private int squareWidth; private int squareHeight; private int boxWidth; private int boxHeight; private int columnCount; private int rowCount; @Override public void repaint(List<Pair<Position, ViewElement>> positionedElements) { clear(positionedElements); paint(positionedElements); paintLines(); } private void clear(List<Pair<Position, ViewElement>> positionedElements) { for (Pair<Position, ViewElement> positionElement : positionedElements) { Position position = positionElement.getKey(); clearBox(position.row(), position.column()); } } private void paint(List<Pair<Position, ViewElement>> positionedElements) { for(Pair<Position, ViewElement> pair : positionedElements){ paintElementAtPosition(pair.getValue(), pair.getKey()); Loading @@ -31,10 +39,15 @@ public class FirefighterGrid extends Canvas implements Grid<ViewElement>{ @Override public void repaint(ViewElement[][] elements) { clear(); paint(elements); paintLines(); } private void clear() { getGraphicsContext2D().clearRect(0,0,getWidth(), getHeight()); } private void paint(ViewElement[][] elements) { for(int column = 0; column < columnCount; column++) for(int row = 0; row < rowCount; row++){ Loading @@ -51,11 +64,13 @@ public class FirefighterGrid extends Canvas implements Grid<ViewElement>{ } @Override public void setDimensions(int columnCount, int rowCount, int squareWidth, int squareHeight) { this.squareWidth = squareWidth; this.squareHeight = squareHeight; public void setDimensions(int columnCount, int rowCount, int boxWidth, int boxHeight) { this.boxWidth = boxWidth; this.boxHeight = boxHeight; this.columnCount = columnCount; this.rowCount = rowCount; super.setWidth(boxWidth * columnCount); super.setHeight(boxHeight * rowCount); } private void paintLines(){ Loading @@ -65,16 +80,20 @@ public class FirefighterGrid extends Canvas implements Grid<ViewElement>{ private void paintVerticalLines() { for(int column = 0; column < columnCount; column++) getGraphicsContext2D().strokeLine(column*squareWidth, 0,column*squareWidth, getHeight()); getGraphicsContext2D().strokeLine(column * boxWidth, 0,column * boxWidth, getHeight()); } private void paintHorizontalLines() { for(int row = 0; row < rowCount; row++) getGraphicsContext2D().strokeLine(0, row*squareHeight, getWidth(), row*squareHeight); getGraphicsContext2D().strokeLine(0, row * boxHeight, getWidth(), row * boxHeight); } private void paintSquare(int row, int column, Color color){ private void paintBox(int row, int column, Color color){ getGraphicsContext2D().setFill(color); getGraphicsContext2D().fillRect(row*squareHeight,column*squareWidth,squareHeight,squareWidth); getGraphicsContext2D().fillRect(column * boxWidth,row * boxHeight, boxWidth, boxHeight); } private void clearBox(int row, int column){ getGraphicsContext2D().clearRect(column * boxWidth,row * boxHeight, boxWidth, boxHeight); } } No newline at end of file
src/main/java/view/Grid.java +1 −2 Original line number Diff line number Diff line Loading @@ -28,8 +28,7 @@ public interface Grid<E> { void repaint(E[][] elements); /** * Set the dimensions of the grid to the specified column count, row count, square width, and square height. * This method adjusts the dimensions of the grid to the given number of columns, number of rows, square width, * Set the dimensions of the grid to the specified number of columns, number of rows, square width, * and square height. * * @param columnCount The new number of columns in the grid. Loading
src/main/resources/view/view.fxml +1 −1 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ mnemonicParsing="false" onAction="#pauseToggleButtonAction" prefHeight="24.0" prefWidth="200.0" styleClass="button" text="Pause"/> </VBox> <FirefighterGrid fx:id="grid" width="1000.0" height="1000.0" <FirefighterGrid fx:id="grid" xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml"> </FirefighterGrid> Loading