import java.awt.*;

/**
  *This class represents the main obstacle in the game
  *
  */
class BrickPile extends CompositePiece{

	/**
	  *Constructor of the BrickPile
	  *@param fieldPtr the PlayingField that holds the BrickPile
	  *@param atPoint1 the upper left hand corner of the BrickPile
	  *@param theView the View that will show the BrickPile
	  */
	public BrickPile(PlayingField fieldPtr,Point atPoint1,BricklesView theView){
		super(fieldPtr,atPoint1);
      	int initialX = atPoint1.x;
      	int initialY = atPoint1.y;
      	int x = initialX;
      	int y = initialY;
		final int numberOfBricks = 6;
      	for(int i=0;i< numberOfBricks;i++){
   			_list.addElement(new Brick((BricklesPlayingField)fieldPtr,new Point(x,y),theView));
      		x = x + 70;
      	}
      	_extent = new Dimension(440,20);
      	_boundingBox = new Rectangle(_currentPosition,_extent);
	}

	/**
	  *Not needed - a no-op
	  */
	public void collideWith(ArcadeGamePiece aPiece, Point atPoint){
	}

	/**
	  *Not needed - a no-op
	  */
	public void collideWithPaddle(Paddle aPaddle,Point atPoint){

	}

	/**
	  *Specifies what happens when the Puck hits inside the BrickPile
	  *@param aPuck the Puck which has hit the BrickPile
	  *@param atPoint the location at which the collision was detetced
	  */ 
	public void collideWithPuck(Puck aPuck, Point atPoint){
		for(int i =0;i < this.getSize();i++){
			if(((Brick)_list.elementAt(i)).isContained(atPoint) && !((Brick)_list.elementAt(i)).isHit()){
      			((Brick)_list.elementAt(i)).collideWithPuck(aPuck,atPoint);
			}
      	}
	}

	/**
	  *Accessor for specific bricks
	  *@param i the index of the Brick in a left to right order
	  */
	public Brick getBrickAt(int i){
   		return (Brick)_list.elementAt(i);
   	}

	/**
	  *Accessor for the size of the BrickPile
	  *@return the number of Bricks in the Pile
	  */
	public int getSize(){
		return _list.size();	
	}
}
