import java.util.*;
import java.awt.*;
import java.awt.Graphics;
import java.awt.Graphics2D;


/**
 *  Board Pannel Class 
 *  <p>
 *  A board pannel represents a single pannel in the Gungi board
 */
public class BoardPanel extends GameObject {
	private static int id = 0;
	private Vector2D pos;
	private Vector2D row_col = null;	//vector row , column
	private BoardPanelView view;
	public int imagen = 0;
	private ArrayList<GameObject> tier;
	public int active = 0;

	/**
     *  Class BoardPanel constructor specifying attributes values
     *
     *  @param xx x position
     *  @param yy y position
     *  @param rc row and column information
     */
	public BoardPanel(int xx, int yy, Vector2D rc){
		super(id++);
		pos = new Vector2D(xx,yy);
		view = new BoardPanelView(this);
		tier = new ArrayList<GameObject>();
		row_col = rc;
	}

	/**
     *  Returns the current position vector
     *
     *  @return pos panel position
     */
	public Vector2D getPosition(){
		return pos;
	}

	/**
     *  Sets the position vector
     *
     *  @param v panel position
     */
	public void setPosition(Vector2D v){}
	
	/**
     *  Returns the current row
     *
     *  @return panel row
     */
	public int getRow(){
		if (row_col==null) {return -1;}
		return row_col.getX();
	}

	/**
     *  Returns the current column
     *
     *  @return panel column
     */
	public int getColumn(){
		if (row_col==null) {return -1;}
		return row_col.getY();
	}

    /**
    *   Returns the depth of the board, usually 0
    *  
    *   @return depth
    */
	public int getDepth(){
		return 0;
	}

	/**
     *  Updates the image of the panel acording to the action
     *
     *  @param act whether the panel is set active or not
     */
	public void updateImg( int act){
		view.updateImg(act);
		this.imagen = act;
	}

	/**
     *  Method for the world to paint this element
     *
     *  @param gra graphics 2d object
     */
	public void paintView(Graphics2D gra) {
        view.paint(gra);
    }

    /**
     *  Method to add a piece to the tower in this panel
     *
     *  @param e action in the panel
     */
    public void addTier(GameObject e){
    	if (tier.size()<3){
    		tier.add(e);
    	}
    }

    /**
     *  Method to remove the piece number e in the tower of this panel
     *
     *  @param e action in the panel
     */
    public void removeTier(int e){
    	if (tier.size()>0){
    		tier.remove(e);
    	}
    }

    /**
     *  Returns the current size of the tower
     *
     *  @return tier size
     */
    public int getTierSize(){
    	return tier.size();
    }

    /**
     *  Returns the Array of pieces in the tower
     *
     *  @return tier pieces
     */
    public ArrayList<GameObject> getTier(){
    	return tier;
    }

    /**
     *  Method to remove all pieces in the tower of this panel
     */
    public void tier_clear(){
    	tier.clear();
    }
}