package CheckerArray;
/**
 * CheckerBoard.java
 *
 *
 * @author Brown University
 */

public class CheckerBoard extends NGP.Containers.DrawingPanel 
  implements CheckerBoardConstants {
  
  private ColorChangingRect[][] _rects;

  public CheckerBoard (NGP.Container container){
    super(container);
    this.setDimension(new java.awt.Dimension(NUM_SQRS * SQR_SIZE,
					     NUM_SQRS * SQR_SIZE));
    _rects= new ColorChangingRect[NUM_SQRS][NUM_SQRS];

    ColorChangingRect rect;

    // first for loop loops through rows
    for ( int row = 0; row < NUM_SQRS; row++ ) {
      // nested for loop loops through cols
      for ( int col = 0; col < NUM_SQRS; col++ ) {
	if ( (row + col) % 2 == 0 ) {
	  rect = new ColorChangingRect(this, java.awt.Color.red,
				       java.awt.Color.white);
	} // end of if ()
	else {
	  rect = new ColorChangingRect(this, java.awt.Color.black,
				       java.awt.Color.blue);
	} // end of else
	// rect's position is determined by its index in array and its
	// size 
	rect.setLocation(new java.awt.Point(col * SQR_SIZE,
					    (NUM_SQRS-row-1) * SQR_SIZE));
	_rects[row][col] = rect;
      } // end of for ()
      
    } // end of for ()
  }

  public void changeRowColor(int row) {
    ColorChangingRect rect;
    for ( int col = 0; col < NUM_SQRS; col++ ) {
      rect = _rects[row][col];
      rect.toggleColor();
    } // end of for ()
  }

  public void changeColColor(int col) {
    
    for ( int row = 0; row < NUM_SQRS; row++ ) {
      _rects[row][col].toggleColor();
    } // end of for ()
  }
}// CheckerBoard

