package model;

public class ArrayGrid implements Grid{

    private Cell[][] cells;
    private final  int numberOfRows ;
    private final int numberOfColumns ;


    public ArrayGrid(int numberOfRows,int numberOfColumns) {
        this.numberOfRows = numberOfRows;
        this.numberOfColumns = numberOfColumns;
        if (numberOfColumns <= 0 || numberOfRows <= 0) {
            throw new IllegalArgumentException();
                }
        else {
            for (int j = 0; j < this.numberOfColumns; j++) {
                for (int i = 0; i < this.numberOfRows; i++) {
                    cells[i][j] = new SquareCell();
                }
            }
        }
    }

    public Cell getCell(int row, int column) {
        return this.cells[row][column];
    }

    public int getNumberOfRows(){
        return this.numberOfRows;
    }
    public int getNumberOfColumns(){
        return  this.numberOfColumns;
    }

    public void color(ColorGenerator colorGenerator){
        for (int j = 0; j < this.numberOfColumns; j++) {
            for (int i = 0; i < this.numberOfRows; i++) {
               SquareCell cell = new SquareCell();
               cells[i][j].setColor(colorGenerator.nextColor(cell));
            }
        }


    }


}