import java.awt.Color; import java.awt.Graphics; import java.util.ArrayList; /** * Represents the 2D grid of Cells used in Conway's Game of Life. */ public class Landscape { /** The backing 2D array of Cells. */ private Cell[][] landscape; /** Probability that each Cell begins alive when reset() is called. */ private double initialChance; /** Constructs a rows x columns Landscape whose Cells are initially dead. */ public Landscape(int rows, int columns) { // TODO Task 2 landscape = new Cell[rows][columns]; initialChance = 0.0; } /** Constructs a rows x columns Landscape using the supplied initial probability. */ public Landscape(int rows, int columns, double chance) { // TODO Task 2 landscape = new Cell[rows][columns]; initialChance = chance; } /** * Constructs a Landscape whose Cell states match the supplied boolean grid. * true means alive; false means dead. */ public Landscape(boolean[][] grid) { // TODO Task 2 landscape = new Cell[grid.length][grid[0].length]; initialChance = 0.0; } /** Recreates all Cells using the Landscape's initial probability. */ public void reset() { // TODO Task 2 } /** @return the number of rows */ public int getRows() { // TODO Task 2 return landscape.length; } /** @return the number of columns */ public int getCols() { // TODO Task 2 return landscape.length == 0 ? 0 : landscape[0].length; } /** Returns the Cell at the requested location. */ public Cell getCell(int row, int col) { // TODO Task 2 return null; } /** * Returns a text view of the Landscape using X for alive and a blank * space for dead, with a newline after each row. */ public String toString() { // TODO Task 2 return ""; } /** Returns all valid neighboring Cells around (row, col), excluding itself. */ public ArrayList getNeighbors(int row, int col) { // TODO Task 3 return new ArrayList(); } /** Advances the Landscape by one simultaneous Game of Life generation. */ public void advance() { // TODO Task 5 } /** * Draws the Landscape. This method is provided; you do not need to change it. */ public void draw(Graphics g, int scale) { for (int row = 0; row < getRows(); row++) { for (int col = 0; col < getCols(); col++) { Cell cell = getCell(row, col); if (cell != null) { g.setColor(cell.getAlive() ? Color.BLACK : Color.gray); g.fillOval(col * scale, row * scale, scale, scale); } } } } /** Use this method for your own small experiments before running the tester. */ public static void main(String[] args) { // Add your own experiments here. } }