
import java.awt.Color;

/*
 * fPartida.java
 *
 * Created on 9 de enero de 2009, 10:56
 */
import java.util.ArrayList;



/**
 *
 * @author  juan antonio
 */
public class fPartida extends javax.swing.JFrame {

    Juego jue;
    //String paleta[]=new String[6];
    Color paleta[]=new Color[6];
    /** Creates new form fPartida */
    public fPartida(Juego j) {
        initComponents();
        jue=j;
        lAviso.setVisible(false);
        lIntroducir.setVisible(false);
        tNomJug.setVisible(false);
        bCrearJug.setVisible(false);
        bContinuar.setVisible(false);
        lAviso2.setVisible(false);
        paleta[0]=java.awt.Color.GREEN;
        paleta[1]=java.awt.Color.RED;
        paleta[2]=java.awt.Color.PINK;
        paleta[3]=java.awt.Color.YELLOW;
        paleta[4]=java.awt.Color.MAGENTA;
        paleta[5]=java.awt.Color.CYAN;
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTitulo = new javax.swing.JLabel();
        lNomPar = new javax.swing.JLabel();
        lNumJug = new javax.swing.JLabel();
        tNomPar = new javax.swing.JTextField();
        sNumJug = new javax.swing.JSlider();
        bCrearPar = new javax.swing.JButton();
        bSalir = new javax.swing.JButton();
        lAviso = new javax.swing.JLabel();
        lIntroducir = new javax.swing.JLabel();
        tNomJug = new javax.swing.JTextField();
        bCrearJug = new javax.swing.JButton();
        bContinuar = new javax.swing.JButton();
        lAviso2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTitulo.setBackground(java.awt.Color.red);
        jTitulo.setFont(new java.awt.Font("Tahoma", 1, 18));
        jTitulo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jTitulo.setText("Datos de partida");
        jTitulo.setOpaque(true);

        lNomPar.setFont(new java.awt.Font("Tahoma", 1, 12));
        lNomPar.setText("Nombre de la partida: ");

        lNumJug.setFont(new java.awt.Font("Tahoma", 1, 12));
        lNumJug.setText("Numero de jugadores:");

        sNumJug.setMajorTickSpacing(1);
        sNumJug.setMaximum(6);
        sNumJug.setMinimum(2);
        sNumJug.setMinorTickSpacing(1);
        sNumJug.setPaintLabels(true);
        sNumJug.setPaintTicks(true);
        sNumJug.setSnapToTicks(true);
        sNumJug.setValue(2);

        bCrearPar.setText("Crear partida");
        bCrearPar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bCrearParActionPerformed(evt);
            }
        });

        bSalir.setText("Salir");
        bSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bSalirActionPerformed(evt);
            }
        });

        lAviso.setFont(new java.awt.Font("Tahoma", 1, 11));
        lAviso.setText("Por favor, introduzca el nombre de la partida.");

        lIntroducir.setFont(new java.awt.Font("Tahoma", 1, 12));
        lIntroducir.setText("Introduzca el nombre del jugador");
        lIntroducir.setOpaque(true);

        bCrearJug.setText("Crear jugador");
        bCrearJug.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bCrearJugActionPerformed(evt);
            }
        });

        bContinuar.setText("Continuar");
        bContinuar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bContinuarActionPerformed(evt);
            }
        });

        lAviso2.setFont(new java.awt.Font("Tahoma", 1, 11));
        lAviso2.setText("Por favor, introduzca el nombre del jugador");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(111, 111, 111)
                        .addComponent(jTitulo))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(30, 30, 30)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(146, 146, 146)
                                .addComponent(bSalir)
                                .addGap(85, 85, 85))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(lNumJug)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
                                .addComponent(sNumJug, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(lNomPar)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(tNomPar, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(41, 41, 41)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(bCrearPar)
                            .addComponent(tNomJug, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lIntroducir, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lAviso, javax.swing.GroupLayout.PREFERRED_SIZE, 274, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(bCrearJug)
                                .addGap(38, 38, 38)
                                .addComponent(bContinuar))
                            .addComponent(lAviso2))))
                .addContainerGap(21, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTitulo)
                .addGap(45, 45, 45)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lNomPar)
                    .addComponent(tNomPar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(51, 51, 51)
                        .addComponent(sNumJug, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(24, 24, 24))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(lNumJug)
                        .addGap(39, 39, 39)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bCrearPar)
                    .addComponent(bSalir))
                .addGap(18, 18, 18)
                .addComponent(lAviso, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(30, 30, 30)
                .addComponent(lIntroducir)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(tNomJug, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(lAviso2)
                .addGap(22, 22, 22)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bCrearJug)
                    .addComponent(bContinuar))
                .addGap(38, 38, 38))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void bSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bSalirActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_bSalirActionPerformed

private void bCrearParActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bCrearParActionPerformed
// TODO add your handling code here:
    String nombre=getTNomPar().getText();
    int numJug=getSNumJug().getValue();
    if(nombre.compareTo("")==0){
            getLAviso().setVisible(true);
    }
    else{
        jue.arrancarJuego(nombre,numJug);
        getBCrearPar().setVisible(false);
        getBSalir().setVisible(false);
        getLAviso().setVisible(false);
        lIntroducir.setBackground(paleta[0]);
        getLIntroducir().setText("Introduzca el nombre del jugador 1:");
        lIntroducir.setVisible(true);
        tNomJug.setVisible(true);
        bCrearJug.setVisible(true);
    }
}//GEN-LAST:event_bCrearParActionPerformed

private void bCrearJugActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bCrearJugActionPerformed
// TODO add your handling code here:
    int creados=jue.getNPartida().getJugadores().size();
    int num=jue.getNPartida().getNumJugadores();
    String nombre=getTNomJug().getText();
    if(nombre.compareTo("")==0){
        lAviso2.setVisible(true);
    }
    else{
        jue.getNPartida().creaJugador(40, nombre, creados+1, paleta[creados]);
        creados++;
        if(creados<num){
            tNomJug.setText("");
            Color bg=paleta[creados];
            lIntroducir.setBackground(bg);
            lIntroducir.setText("Introduzca el nombre del jugador "+(creados+1)+":");
            lAviso2.setVisible(false);
            
        }
        else{
            bCrearJug.setVisible(false);
            bContinuar.setVisible(true);
        }
    }
}//GEN-LAST:event_bCrearJugActionPerformed

private void bContinuarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bContinuarActionPerformed
// TODO add your handling code here:
    this.setVisible(false);
    ArrayList<Territorio> l=new ArrayList();
    l=jue.getNPartida().getTerritorio();
    fTablero ft=new fTablero(jue.getNPartida());
    ft.setVisible(true);
    int num=jue.getNPartida().getNumTerritorios();
    int i;
    for(i=0; i<num; i++){
        l.get(i).addObserver(ft);
    }
}//GEN-LAST:event_bContinuarActionPerformed

    /**
    * @param args the command line arguments
    */
    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bContinuar;
    private javax.swing.JButton bCrearJug;
    private javax.swing.JButton bCrearPar;
    private javax.swing.JButton bSalir;
    private javax.swing.JLabel jTitulo;
    private javax.swing.JLabel lAviso;
    private javax.swing.JLabel lAviso2;
    private javax.swing.JLabel lIntroducir;
    private javax.swing.JLabel lNomPar;
    private javax.swing.JLabel lNumJug;
    private javax.swing.JSlider sNumJug;
    private javax.swing.JTextField tNomJug;
    private javax.swing.JTextField tNomPar;
    // End of variables declaration//GEN-END:variables

    public javax.swing.JButton getBContinuar() {
        return bContinuar;
    }

    public void setBContinuar(javax.swing.JButton bContinuar) {
        this.bContinuar = bContinuar;
    }

    public javax.swing.JButton getBCrearJug() {
        return bCrearJug;
    }

    public void setBCrearJug(javax.swing.JButton bCrearJug) {
        this.bCrearJug = bCrearJug;
    }

    public javax.swing.JButton getBCrearPar() {
        return bCrearPar;
    }

    public void setBCrearPar(javax.swing.JButton bCrearPar) {
        this.bCrearPar = bCrearPar;
    }

    public javax.swing.JButton getBSalir() {
        return bSalir;
    }

    public void setBSalir(javax.swing.JButton bSalir) {
        this.bSalir = bSalir;
    }

    public javax.swing.JLabel getJTitulo() {
        return jTitulo;
    }

    public void setJTitulo(javax.swing.JLabel jTitulo) {
        this.jTitulo = jTitulo;
    }

    public javax.swing.JLabel getLAviso() {
        return lAviso;
    }

    public void setLAviso(javax.swing.JLabel lAviso) {
        this.lAviso = lAviso;
    }

    public javax.swing.JLabel getLIntroducir() {
        return lIntroducir;
    }

    public void setLIntroducir(javax.swing.JLabel lIntroducir) {
        this.lIntroducir = lIntroducir;
    }

    public javax.swing.JLabel getLNomPar() {
        return lNomPar;
    }

    public void setLNomPar(javax.swing.JLabel lNomPar) {
        this.lNomPar = lNomPar;
    }

    public javax.swing.JLabel getLNumJug() {
        return lNumJug;
    }

    public void setLNumJug(javax.swing.JLabel lNumJug) {
        this.lNumJug = lNumJug;
    }

    public javax.swing.JSlider getSNumJug() {
        return sNumJug;
    }

    public void setSNumJug(javax.swing.JSlider sNumJug) {
        this.sNumJug = sNumJug;
    }

    public javax.swing.JTextField getTNomJug() {
        return tNomJug;
    }

    public void setTNomJug(javax.swing.JTextField tNomJug) {
        this.tNomJug = tNomJug;
    }

    public javax.swing.JTextField getTNomPar() {
        return tNomPar;
    }

    public void setTNomPar(javax.swing.JTextField tNomPar) {
        this.tNomPar = tNomPar;
    }

}
