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

refactoring grid

parent 7aa7b495
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -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.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment