
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.concurrent.ThreadLocalRandom;

import java.util.ArrayList;
import java.util.*;

public class Deck {
    private ArrayList<Card> deck = new ArrayList<Card>();            
    
    public Deck(){
        //mazo de 9 cartas
        int i;
        int lineCount=0;
        try{
            BufferedReader buf = new BufferedReader(new FileReader("src\\MediaResources\\deck1.txt"));
            String lineJustFetched = null;
            String[] wordsArray;

            while(true){
                lineJustFetched = buf.readLine();
                if(lineJustFetched == null){  
                    break; 
                }else{
                    wordsArray = lineJustFetched.split("\t");
                    int lineID = Integer.parseInt(wordsArray[0]);
                        Card carta = new Card(lineID);   
                        deck.add(carta);
                        //deck[lineCount] = new Card(Integer.parseInt(wordsArray[0])); //crea el mazo desde el .txt del mazo
                        lineCount++;
                    }
                
                }
            

            

            buf.close();

        }catch(Exception e){
            e.printStackTrace();
        }
        //randomizando el deck, para que cada partida sea distinta:
        //List<Card> list = Arrays.asList(deck);
        Collections.shuffle(deck);
        //list.toArray(deck);
        
        
    }
    public ArrayList<Card> getDECK(){
        return deck;
    }
    public Card getCard(int pos){
        Card temp = deck.get(pos);
        deck.remove(pos);
        return temp;
    }
    public String getCardIDPath(int pos){
        Card card = deck.get(pos);
        String IDstr = Integer.toString(card.getID());
        String IDlocation = "/MediaResources/" + IDstr +".jpg";
        System.out.format("from deck: %s",IDlocation);
        return IDlocation;
    }
    public void delFromDECK(Card[] a, int del) {
    System.arraycopy(a,del+1,a,del,a.length-1-del);
}
    public String deckSize(){
        return Integer.toString(deck.size());
    }
    
    
}
