package ManicMiner;

import javax.microedition.lcdui.game.*;
import java.io.*;
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author supervisor
 */
public class FabricaNivel {

    RemakeManicMiner rm;
    Personaje pj;

    public FabricaNivel(){
       
    }


    public void setGameDesign(RemakeManicMiner rm){
        this.rm = rm;
    }
    TiledLayer fabricaTile(int nivel){
        TiledLayer t = null;
        try{
            switch(nivel){
                case 0: t = rm.getMapaTilesPresentacion();break;
                case 1: t = rm.getTilesMapa1(); break;
                case 2: t = rm.getMapaTiles2(); break;
                case 3: t = rm.getTilesMapa3(); break;
                case 4: t = rm.getTilesMapa4(); break;
                case 5: t = rm.getTilesMapa5(); break;
                default: System.out.println("No existe el nivel especificado");
            }
        }catch (IOException e){
            System.out.println(e);
        }

        return t;
    }

    TiledLayer fabricaTileColision(int nivel){
        TiledLayer t = null;
        try{
            switch(nivel){
                case 0: t= rm.getPresentacionColision();break;
                case 1: t= rm.getColisionMapa1(); break;
                case 2: t= rm.getColisionMapa2(); break;
                case 3: t = rm.getColisionMapa3(); break;
                case 4: t = rm.getColisionMapa4(); break;
                case 5: t = rm.getColisionMapa5(); break;
                default: System.out.println("No existe el nivel de tile colision especificado");
            }
        }catch (IOException e){
            System.out.println(e);
        }
        
        return t;

    }

    IMonstruo [] fabricaMonstruos(int nivel){
        IMonstruo [] m = null;
        Sprite sp;
        try{
        switch(nivel){
            case 0: m = null; break;
            case 1:
                //NIVEL 1
                m = new IMonstruo[1];
                sp = rm.getMonstruoTrompeta();

                m[0] = new Monstruo(sp, 2 , true, 64, sp.getY(), 135, sp.getY());

                break;

            case 2:
                //NIVEL 2 ///////////
                //Monstruo 1
                m = new IMonstruo[2];
                sp = rm.getPinguino1();

                m[0] = new Monstruo(sp, 2 , false,8 ,sp.getY(),160 , sp.getY());

                sp = rm.getPingu();

                m[1] = new Monstruo(sp, 2, false,96 ,sp.getY(),248 , sp.getY());
                break;
            case 3:
                //NIVEL 3 ///////////
                //Monstruo 1
                m = new IMonstruo[2];
                sp = rm.getAvestruz1Mapa3();

                m[0] = new Monstruo(sp, 2, false, 8, sp.getY(), 144, sp.getY());

                sp = rm.getAvestruz2Mapa3();

                m[1] = new Monstruo(sp, 2, false, 144, sp.getY(), 248,sp.getY());
                break;

            case 4:
                //NIVEL 4 ////////

                m = new IMonstruo[2];
                sp = rm.getFoca1Mapa4();

                m[0] = new Monstruo(sp, 2, true, 8, sp.getY(), 96, sp.getY());

                sp = rm.getFoca2Mapa4();

                m[1] = new Monstruo(sp, 2, true, 48, sp.getY(), 136, sp.getY());
                break;

            case 5:
                /// NIVEL 5 ///////

                m = new IMonstruo[3];

                sp = rm.getWc1Mapa5();
                m[0] = new Monstruo(sp, 2, false, 8, sp.getY(), 112, sp.getY());

                sp = rm.getWc2Mapa5();
                m[1] = new Monstruo(sp, 2, false, 32, sp.getY(), 112, sp.getY());

                sp = rm.getEugenioMapa5();
                m[2] = new Monstruo(sp, 1, true, sp.getX(), 0, sp.getX(), 104);
                break;

            default: System.out.println("No existe monstruos en ese nivel");
        }
        }catch (IOException e){
            System.out.println("Error con los monstruoss"+e);
        }
        
        return m;
    }

    void updaterNivel(LayerManager lm,int nivel){
        try{
            switch(nivel){
                case 0: rm.updateLayerManagerForPresentacion(lm);break;
                case 1: rm.updateLayerManagerForFase1(lm);break;
                case 2: rm.updateLayerManagerForFase2(lm);break;
                case 3: rm.updateLayerManagerForFase3(lm);break;
                case 4: rm.updateLayerManagerForFase4(lm);break;
                case 5: rm.updateLayerManagerForFase5(lm);break;
                default:System.out.println("Dicho nivel no puede actualizar o no existe");
            }

        }catch(IOException e){
            System.out.println(e);
        }

    }

    int getLlaves (int nivel){
        int llaves = 0;
        switch(nivel){
            case 0: llaves = 0;break;
            case 1: llaves = 5;break;
            case 2: llaves = 5;break;
            case 3: llaves = 5;break;
            case 4: llaves = 5;break;
            case 5: llaves = 5;break;
            default: System.out.println("ERROR: LLaves no existen en ese nivel ");
        }

        return llaves;
    }

    Personaje fabricaPersonaje(int nivel){
       if(pj==null){
        try{
        pj = new Personaje(rm.getManicMinerPJ());
        }catch(IOException e){
            System.out.println(e);
        }
       }
       else{
           try{
           pj.setSprite(rm.getManicMinerPJ());
           pj.mirarDer();
            }catch(IOException e){
            System.out.println(e);
        }

       }

       if(nivel==4){
           pj.mirarIzq();
       }
       
       return pj;


    }

    int fabricaTileAnimLlave(int nivel){
        int tileAnimLlave = -10;
        switch(nivel){
            case 0: tileAnimLlave = -10; break;
            case 1: tileAnimLlave = rm.llaveTilesMapa1; break;
            case 2: tileAnimLlave = rm.raquetaAnimMapaTiles2; break;
            case 3: tileAnimLlave = rm.llaveMapa3TilesMapa3; break;
            case 4: tileAnimLlave = rm.llaveMapa4TilesMapa4; break;
            case 5: tileAnimLlave = rm.llaveMapa5TilesMapa5; break;
            default: System.out.println("No existe la animacion de la llave en ese nivel");
        }

        return tileAnimLlave;
    }

    int [] fabricaLlaveSeq(int nivel){
        int [] seq = null;
        switch(nivel){
            case 0: seq = null; break;
            case 1: seq = rm.llaveseq001; break;
            case 2: seq = rm.raquetaAnimseq001; break;
            case 3: seq = rm.llaveMapa3seq001; break;
            case 4: seq = rm.llaveMapa4seq001; break;
            case 5: seq = rm.llaveMapa5seq001; break;
            default: System.out.println("No existe la secuencia de la llave en ese nivel");
        }
        return seq;
    }

    int fabricaTileAnimCinta(int nivel){
        int tileAnimCinta = -10;
        switch(nivel){
            case 0: tileAnimCinta = -10; break;
            case 1: tileAnimCinta = rm.DeslizadorTilesMapa1; break;
            case 2: tileAnimCinta = rm.CintaAnimMapaTiles2; break;
            case 3: tileAnimCinta = rm.cintaMapa3TilesMapa3; break;
            case 4: tileAnimCinta = rm.cintaMapa4TilesMapa4; break;
            case 5: tileAnimCinta = rm.cintaMapa5TilesMapa5; break;
            default: System.out.println("No existe la animacion de la cinta en ese nivel");
        }

        return tileAnimCinta;
    }

    int [] fabricaCintaSeq(int nivel){
        int [] seq = null;

        switch(nivel){
            case 0: seq = null; break;
            case 1: seq = rm.Deslizadorseq001; break;
            case 2: seq = rm.CintaAnimseq001; break;
            case 3: seq = rm.cintaMapa3seq001; break;
            case 4: seq = rm.cintaMapa4seq001; break;
            case 5: seq = rm.cintaMapa5seq001; break;
            default: System.out.println("No existe la secuencia de la cinta en ese nivel");
        }

        return seq;
    }

    /*
    int [][] fabricaTilesAnimacion(int nivel){

        int [][] tileAndSeq = null;

        switch(nivel){
            case 1: tileAndSeq = new int[2][]; tileAndSeq[0] = rm.llaveseq001; tileAndSeq[1] = rm.Deslizadorseq001; break;
            default: System.out.println("No existe los tiles animados o la secuancia en ese nivel");
        }

        return tileAndSeq;
    }
    */

    public Sprite fabricaPuerta(int nivel){
        Sprite puerta = null;

        try{
            switch(nivel){
                case 0: puerta = rm.getPuerta1(); break;
                case 1: puerta = rm.getPuerta1(); break;
                case 2: puerta = rm.getPuerta2(); break;
                case 3: puerta = rm.getPuertaMapa3(); break;
                case 4: puerta = rm.getPuertaMapa4(); break;
                case 5: puerta = rm.getPuertaMapa5(); break;
                default: System.out.println("No existe Sprite activo de puerta para dicho nivel");
            }
        }catch(IOException e){
            System.out.println(e);
        }

        return puerta;

    }

}
