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

some renaming of methods for clarity

parent ba6f7943
No related branches found
No related tags found
No related merge requests found
......@@ -67,10 +67,10 @@ public class Controller {
updatedSquares.add(new Pair<>(updatedPosition, viewElement));
}
grid.repaint(updatedSquares);
updateLabel(board.stepNumber());
updateGenerationLabel(board.stepNumber());
}
private void repaintBoard(){
private void repaintGrid(){
int columnCount = board.columnCount();
int rowCount = board.rowCount();
ViewElement[][] viewElements = new ViewElement[rowCount][columnCount];
......@@ -78,7 +78,7 @@ public class Controller {
for(int row = 0; row < rowCount; row++)
viewElements[row][column] = getViewElement(board.getState(new Position(row, column)));
grid.repaint(viewElements);
updateLabel(board.stepNumber());
updateGenerationLabel(board.stepNumber());
}
private ViewElement getViewElement(List<ModelElement> squareState) {
......@@ -120,14 +120,14 @@ public class Controller {
this.pause();
board.reset();
pauseToggleButton.setSelected(true);
repaintBoard();
repaintGrid();
}
public void initialize(int squareWidth, int squareHeight, int columnCount,
int rowCount, int initialFireCount, int initialFirefighterCount) {
grid.initialize(squareWidth, squareHeight, columnCount, rowCount);
this.setModel(new FirefighterBoard(columnCount, rowCount, initialFireCount, initialFirefighterCount));
repaintBoard();
repaintGrid();
}
public void oneStepButtonAction() {
......@@ -135,7 +135,7 @@ public class Controller {
updateBoard();
}
private void updateLabel(int value){
private void updateGenerationLabel(int value){
generationNumberLabel.setText(Integer.toString(value));
}
}
\ No newline at end of file
......@@ -10,10 +10,10 @@ public class FirefighterBoard implements Board<List<ModelElement>> {
private final int rowCount;
private final int initialFireCount;
private final int initialFirefighterCount;
List<Position> firefighterPositions;
Set<Position> firePositions;
List<Position> firefighterNewPositions;
int step = 0;
private List<Position> firefighterPositions;
private Set<Position> firePositions;
private int step = 0;
private final Random randomGenerator = new Random();
public FirefighterBoard(int columnCount, int rowCount, int initialFireCount, int initialFirefighterCount) {
this.columnCount = columnCount;
......@@ -33,7 +33,7 @@ public class FirefighterBoard implements Board<List<ModelElement>> {
}
private Position randomPosition() {
return new Position((int) (Math.random() * rowCount), (int) (Math.random() * columnCount));
return new Position(randomGenerator.nextInt(rowCount), randomGenerator.nextInt(columnCount));
}
@Override
......@@ -85,14 +85,15 @@ public class FirefighterBoard implements Board<List<ModelElement>> {
private List<Position> activateFirefighters() {
List<Position> result = new ArrayList<>();
firefighterNewPositions = new ArrayList<>();
List<Position> firefighterNewPositions = new ArrayList<>();
for (Position firefighterPosition : firefighterPositions) {
Position newFirefighterPosition = neighborClosestToFire(firefighterPosition);
result.add(firefighterPosition);
firefighterNewPositions.add(newFirefighterPosition);
extinguish(newFirefighterPosition);
result.add(firefighterPosition);
result.add(newFirefighterPosition);
List<Position> neighborFirePositions = neighbors(newFirefighterPosition).stream().filter(firePositions::contains).toList();
List<Position> neighborFirePositions = neighbors(newFirefighterPosition).stream()
.filter(firePositions::contains).toList();
for(Position firePosition : neighborFirePositions)
extinguish(firePosition);
result.addAll(neighborFirePositions);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment