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

refactoring grid

parent 7aa7b495
Branches
No related tags found
No related merge requests found
Pipeline #22279 passed
...@@ -19,10 +19,18 @@ public class FirefighterGrid extends Canvas implements Grid<ViewElement>{ ...@@ -19,10 +19,18 @@ public class FirefighterGrid extends Canvas implements Grid<ViewElement>{
@Override @Override
public void repaint(List<Pair<Position, ViewElement>> positionedElements) { public void repaint(List<Pair<Position, ViewElement>> positionedElements) {
clear(positionedElements);
paint(positionedElements); paint(positionedElements);
paintLines(); 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) { private void paint(List<Pair<Position, ViewElement>> positionedElements) {
for(Pair<Position, ViewElement> pair : positionedElements){ for(Pair<Position, ViewElement> pair : positionedElements){
paintElementAtPosition(pair.getValue(), pair.getKey()); paintElementAtPosition(pair.getValue(), pair.getKey());
...@@ -31,10 +39,15 @@ public class FirefighterGrid extends Canvas implements Grid<ViewElement>{ ...@@ -31,10 +39,15 @@ public class FirefighterGrid extends Canvas implements Grid<ViewElement>{
@Override @Override
public void repaint(ViewElement[][] elements) { public void repaint(ViewElement[][] elements) {
clear();
paint(elements); paint(elements);
paintLines(); paintLines();
} }
private void clear() {
getGraphicsContext2D().clearRect(0,0,getWidth(), getHeight());
}
private void paint(ViewElement[][] elements) { private void paint(ViewElement[][] elements) {
for(int column = 0; column < columnCount; column++) for(int column = 0; column < columnCount; column++)
for(int row = 0; row < rowCount; row++){ for(int row = 0; row < rowCount; row++){
...@@ -77,4 +90,8 @@ public class FirefighterGrid extends Canvas implements Grid<ViewElement>{ ...@@ -77,4 +90,8 @@ public class FirefighterGrid extends Canvas implements Grid<ViewElement>{
getGraphicsContext2D().setFill(color); getGraphicsContext2D().setFill(color);
getGraphicsContext2D().fillRect(row*squareHeight,column*squareWidth,squareHeight,squareWidth); 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> { ...@@ -28,8 +28,7 @@ public interface Grid<E> {
void repaint(E[][] elements); void repaint(E[][] elements);
/** /**
* Set the dimensions of the grid to the specified column count, row count, square width, and square height. * Set the dimensions of the grid to the specified number of columns, number of rows, square width,
* This method adjusts the dimensions of the grid to the given number of columns, number of rows, square width,
* and square height. * and square height.
* *
* @param columnCount The new number of columns in the grid. * @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