public void createNextGeneration() { StringBuffer nextGenerationContent = new StringBuffer(); int maxRow = currentGridContent.getWidth(); int maxColumn = currentGridContent.getHeight(); // TODO: simplify this code for (int y = 0; y < maxRow; y++) { for (int x = 0; x < maxColumn; x++) { Cell currentCell = currentGridContent.getCellAt(x, y); int neighbourCount = currentGridContent.getLiveNeighboursAt(x, y); Cell nextCell = null; if (currentCell == Cell.LIVE_CELL) { if ((neighbourCount == 2) || (neighbourCount == 3)) { nextCell = LIVE_CELL; } else { nextCell = DEAD_CELL; } } else { if (neighbourCount == 3) { nextCell = LIVE_CELL; } else { nextCell = DEAD_CELL; } } nextGenerationContent.append(nextCell); } nextGenerationContent.append(NEW_LINE); } nextGenerationContent.append(NEW_LINE); currentGridContent = new Grid(nextGenerationContent.toString()); }
public Cell getCellAt(final int row, final int column) { return currentGridContent.getCellAt(column, row); }