Keep those PRs small 1

PHOTO EMBED

Sat Sep 25 2021 20:11:37 GMT+0000 (UTC)

Saved by @mikelowe08 #java

public void initialiseCells() {
  for (int row = 0; row < grid.getRows(); row++) {
    for (int column = 0; column < grid.getColumns(); column++) {
      initialiseCell(new Coordinates(row, column));
    }
  }
}

private void initialiseCell(Coordinates coordinates) {
  Cell cell = new Cell();

  addAlivePropertyListener(cell);
  addClickEventHandler(cell);

  grid.add(cell, coordinates);
}

private void addAlivePropertyListener(Cell cell) {
  cell.aliveProperty()
    .addListener(newValue -> setAliveStyle(cell, newValue));
}

private void setAliveStyle(Cell cell, boolean isAlive) {
  List<String> styleClass = cell.getStyleClass();
  if (isAlive) {
    styleClass.add(ALIVE_STYLE_CLASS);
  } else {
    styleClass.remove(ALIVE_STYLE_CLASS);
  }
}

private void addClickEventHandler(Cell cell) {
  cell.addEventHandler(MouseEvent.MOUSE_CLICKED,
    event -> cell.toggleAlive());
}

public void resetCells() {
  for (int row = 0; row < grid.getRows(); row++) {
    for (int column = 0; column < grid.getRows(); column++) {
      resetCell(new Coordinates(row, column));
    }
  }
}

private void resetCell(Coordinates coordinates) {
  Cell cell = grid.get(coordinates);

  cell.aliveProperty().setValue(false);
}
content_copyCOPY