import java.util.*;
import java.awt.*;
import java.io.*;


// Maintains a rectangular grid of Cells.
// ----------------------------------------------------------------------
class Grid {

    // The grid will be stored in a 2D array of Cells.
    Cell [][] theGrid;


    // Constructor.  Create an empty Grid with r rows and c columns.
    // ------------------------------------------------------------------
    public Grid (int r, int c) {
        theGrid = new Cell[r][c];
        setEmpty();
    }
    
    // = the number of rows in my grid.
    // ------------------------------------------------------------------
    public int numRows () {
        return theGrid.length;
    }
    
    // = the number of columns in my grid.
    // ------------------------------------------------------------------
    public int numCols () {
        return theGrid[0].length;
    }
    
    // Create a LiveCell at (row,col) in my grid.
    // ------------------------------------------------------------------
    public void addLiveCell (int row, int col) {
        theGrid[row][col] = new LiveCell ();
    }

    // Set my grid to all EmptyCells.
    // ------------------------------------------------------------------
    private void setEmpty () {
        int row;
        for (row = 0; row < numRows(); row++) {
            int col;
            for (col = 0; col < numCols(); col++) {
                theGrid[row][col] = new EmptyCell ();
            }
        }
    }
    
    // Print row r of my grid of cells to standard output.
    // ------------------------------------------------------------------
    private void showTextRow (int r) {

        int c;  // The current column.
        for (c = 0; c < numCols(); c++) {
            theGrid[r][c].showText ();
        }

    }

    // Print my grid of cells to standard output.
    // ------------------------------------------------------------------
    public void showText () {
        
        int r;  // The current row.
        for (r = 0; r < numRows(); r++) {
            showTextRow (r);
            System.out.println ("");
        }
        
        System.out.println ("");
    }


    // Show row r of my grid of cells graphically.
    // ------------------------------------------------------------------
    private void displayRow (int r, Graphics g) {

        int c;  // The current column.
        for (c = 0; c < numCols(); c++) {
            theGrid[r][c].display ( (2+c)*Cell.size,
                                    (3+r)*Cell.size, g);
        }

    }


    // Show my grid of cells graphically.
    // ------------------------------------------------------------------
    public void display (Graphics g) {
        int row;
        for (row = 0; row < numRows(); row++) {
            displayRow (row, g);
        }
    }


    // Compute the next generation of cells and store it in theGrid.
    // ------------------------------------------------------------------
    public void nextGeneration () {
    
    // >> Fill in the body of this method. <<

    }
}
