/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JFcomprobacion.java
 *
 * Created on 21-jul-2010, 11:21:29
 */

package vistas;

import java.util.ArrayList;
import java.util.List;
import javax.swing.DefaultListModel;

/**
 *
 * @author Adrian
 */
public class JFcomprobacion extends javax.swing.JFrame {

    JFprincipal p = new JFprincipal();
    Boolean realizado;

    /** Creates new form JFcomprobacion */
    public JFcomprobacion() {
        initComponents();
        realizado = false;
    }

    /** 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() {

        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jButton4 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        saldo = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        premios = new javax.swing.JList();
        jLabel3 = new javax.swing.JLabel();
        ganado = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
        });

        jButton1.setText("Ver mis columnas");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Ver combinacion ganadora");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setFont(new java.awt.Font("Tahoma", 1, 14));
        jButton3.setForeground(new java.awt.Color(0, 102, 0));
        jButton3.setText("Realizar escrutinio");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vistas/logo_primitiva_tr.gif"))); // NOI18N

        jButton4.setText("Aceptar");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel2.setForeground(new java.awt.Color(0, 102, 0));
        jLabel2.setText("Saldo:");

        saldo.setFont(new java.awt.Font("Tahoma", 1, 14));
        saldo.setText("23");

        jScrollPane2.setViewportView(premios);

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel3.setForeground(new java.awt.Color(0, 102, 0));
        jLabel3.setText("Ganado:");

        ganado.setFont(new java.awt.Font("Tahoma", 1, 14));
        ganado.setText("0 €");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 419, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 202, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addGap(29, 29, 29)
                                .addComponent(ganado)
                                .addGap(2, 2, 2))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(18, 18, 18)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 286, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(36, 36, 36)
                                .addComponent(jLabel2)
                                .addGap(29, 29, 29)
                                .addComponent(saldo)))))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(346, Short.MAX_VALUE)
                .addComponent(jButton4)
                .addGap(22, 22, 22))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addGap(18, 18, 18)
                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(ganado)
                    .addComponent(jLabel2)
                    .addComponent(saldo))
                .addGap(8, 8, 8)
                .addComponent(jButton4)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    //Aceptamos y cerramos el formulario
    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
        dispose();
    }//GEN-LAST:event_jButton4ActionPerformed
    
    //Pulsamos ver ganadora
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        JFverganadora v = new JFverganadora();
        v.p = this.p;
        v.show();
    }//GEN-LAST:event_jButton2ActionPerformed

    //Pulsamos ver nuestras columnas
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        JFvercolumnas c = new JFvercolumnas();
        c.p = this.p;
        c.show();
    }//GEN-LAST:event_jButton1ActionPerformed

    //Cuando se activa el formulario
    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
        // TODO add your handling code here:
        saldo.setText(String.valueOf(p.cliente.getSaldo())+ " €");
    }//GEN-LAST:event_formWindowActivated

    //Pulsamos realizar escrutinio
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        if(realizado == false){
        DefaultListModel mod=new DefaultListModel(); //los premios
        List <Integer> gan = p.cliente.getGanadora(); //la ganadora
        List <Integer> col; //la columna mia
        List <Integer> pre = p.game.getPremios();
        int numero;
        int aciertos=0;
        int valorganado=0; //lo que vamos ganando
        int i = 0;
        int aux = 0;
        while(i<p.cliente.getNumeroColumna()){
            col = p.cliente.getColumnas().get(i).getNumeros(); //primera columna y sucesivas
            while(aux<6){
                numero = gan.get(aux); //primer numero y sucesivos cada vez
                for(int j=aux;j==aux;j++){
                    if(col.get(j) == numero){ //si esta el numero en esta columna
                     aciertos++;
                     j=6; //Si hay coincidencia en la columna que acabe
                    }
                }
                aux++;
                }
                if(aciertos == 6){
                    mod.addElement("6 aciertos en la columna "+ String.valueOf(i+1) + "   || "+pre.get(3)+" € ganados"); //añadimos los aciertos
                    p.cliente.aumentarSaldo(pre.get(3));
                    valorganado+=pre.get(3);
                }
                else if(aciertos == 5){
                    mod.addElement("5 aciertos en la columna "+ String.valueOf(i+1)+ "   || "+pre.get(2)+" € ganados");
                    p.cliente.aumentarSaldo(pre.get(2));
                    valorganado+=pre.get(2);
                }
                else if(aciertos == 4){
                    mod.addElement("4 aciertos en la columna "+ String.valueOf(i+1)+ "   || "+pre.get(1)+" € ganados");
                    p.cliente.aumentarSaldo(pre.get(1));
                    valorganado+=pre.get(1);
                }
                else if(aciertos == 3){
                    mod.addElement("3 aciertos en la columna "+ String.valueOf(i+1+ "   || "+pre.get(0)+" € ganados"));
                    p.cliente.aumentarSaldo(pre.get(0));
                    valorganado+=pre.get(0);
                }
                else
                    mod.addElement("Ningun acierto en la columna "+ String.valueOf(i+1));
                premios.setModel(mod); //Metemos el nuevo modelo con los aciertos
                aciertos = 0;
                i++;
                aux=0;
        }
        saldo.setText(String.valueOf(p.cliente.getSaldo())+" €");
        ganado.setText(String.valueOf(valorganado)+" €");
        realizado = true;
        }
        else{
            JFerrores er = new JFerrores();
            er.setTitle("Escrutinio realizado");
            er.mensajedeerror.setText("Solo puede realizar el escrutinio una vez");
            er.show();
        }
    }//GEN-LAST:event_jButton3ActionPerformed

    /**
    * @param args the command line arguments
    */
    /*public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new JFcomprobacion().setVisible(true);
            }
        });
    }*/

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel ganado;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JList premios;
    private javax.swing.JLabel saldo;
    // End of variables declaration//GEN-END:variables

}
