diff --git a/src/main/java/view/FirefighterGrid.java b/src/main/java/view/FirefighterGrid.java index c4df123389965a8116673a4da1e8a5725410bea2..c1b2274637f93e4a2482faa9d2a5559211b31dc6 100644 --- a/src/main/java/view/FirefighterGrid.java +++ b/src/main/java/view/FirefighterGrid.java @@ -19,10 +19,18 @@ public class FirefighterGrid extends Canvas implements Grid<ViewElement>{ @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(); + clearSquare(position.row(), position.column()); + } + } + private void paint(List<Pair<Position, ViewElement>> positionedElements) { for(Pair<Position, ViewElement> pair : positionedElements){ paintElementAtPosition(pair.getValue(), pair.getKey()); @@ -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++){ @@ -77,4 +90,8 @@ public class FirefighterGrid extends Canvas implements Grid<ViewElement>{ getGraphicsContext2D().setFill(color); getGraphicsContext2D().fillRect(row*squareHeight,column*squareWidth,squareHeight,squareWidth); } + + private void clearSquare(int row, int column){ + getGraphicsContext2D().clearRect(row*squareHeight,column*squareWidth,squareHeight,squareWidth); + } } \ No newline at end of file diff --git a/src/main/java/view/Grid.java b/src/main/java/view/Grid.java index d87897bac70a30d297efe6c00b9bc5e23a8206e2..b95d59f622a86b41f2a41261b8b27aaf2e911dfb 100644 --- a/src/main/java/view/Grid.java +++ b/src/main/java/view/Grid.java @@ -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.