
import java.util.ArrayList;

public class Field {
    private final ArrayList<CardInPlay> field;
    private boolean[] slotArray;//arreglod de 5 espacios que dice si el espacio esta lleno
    private int size;
    
    private static final int NO_POS = 5;
    private static final int FACEUP_ATKPOS = 1;
    private static final int FACEUP_DEFPOS = 2;
    private static final int FACEDOWN_DEFPOS = 3;
    
    public Field(){
        slotArray = new boolean[5];
        field = new ArrayList<CardInPlay>();
        size = 0;
        int i;
        for(i=0;i<5;i++){
            field.add(null);
            slotArray[i] = false;
        }
    }
    public boolean isFieldFull(){
        //return slotArray[0]&&slotArray[1]&&slotArray[2]&&slotArray[3]&&slotArray[4];
        return (size == 5);
    }
    public void playCard(Card card, int battlePos){
        if(!this.isFieldFull()){
            int i;
            for(i=0;i<5;i++){
                if (!slotArray[i]) break;
            }
            field.set(i, new CardInPlay(card.getID(), battlePos));
            slotArray[i] = true;
            size++;
        }
    }
    public void removeCard(int pos){
      if(slotArray[pos])
      {         //ArrayList<Card> temp = new ArrayList<Card>();
         //field.set(pos, null);
         field.set(pos, null);
         slotArray[pos] = false;
         size--;
      }
    }
    public int getBattlePos(int index)
    {
        if(field.get(index) == null) return NO_POS;
        else return field.get(index).getBattlePos();
    }
    public CardInPlay getCard(int pos){
        return field.get(pos);    
    }
    public int getSize(){
        return size;
    }
    public void changeBattlePos(int index){
         field.get(index).changeBattlePos();
    }
    public void forceBattlePos(int index){
         field.get(index).forceBattlePos();
    }
        public int getDamage(int pos){
        if (field.get(pos).getBattlePos()==FACEUP_ATKPOS){
            return field.get(pos).getATK();
        }
        else return field.get(pos).getDEF();
    }
}
