package Globales;
import villa1.*;
import Personajes.*;
import java.io.*;
import java.util.*;


/*
 * Cargar.java
 *
 * Created on 28-ago-2009, 0:18:44
 */

/**
 *
 * @author Xabier
 */
public final class CBatalla extends Inicio {
boolean fin = false;
    /** Creates new form Cargar */
    public CBatalla() {
        initComponents();
    }

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

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        btnAtacar = new javax.swing.JButton();
        btnDefender = new javax.swing.JButton();
        btnPasarTurno = new javax.swing.JButton();
        btnUsarObjeto = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        barraPers = new javax.swing.JProgressBar();
        barraRiv = new javax.swing.JProgressBar();
        cajaInfoPers = new javax.swing.JTextField();
        cajaInfoRiv = new javax.swing.JTextField();
        cajaRes = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        btnContinuar = new javax.swing.JButton();
        checkboxCont = new javax.swing.JCheckBox();
        listAtcEsp = new javax.swing.JComboBox();
        btnEjecutar = new javax.swing.JButton();
        btnEnv = new javax.swing.JButton();
        btnQue = new javax.swing.JButton();
        btnCon = new javax.swing.JButton();
        btnPar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("RpG Java - Campo Batalla");

        jLabel1.setFont(new java.awt.Font("Tahoma", 2, 24));
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText(". Campo Batalla .");

        jLabel2.setText("Clicka en la acción que quieres realizar:");

        btnAtacar.setText("Atacar");
        btnAtacar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAtacarActionPerformed(evt);
            }
        });

        btnDefender.setText("Defender");
        btnDefender.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDefenderActionPerformed(evt);
            }
        });

        btnPasarTurno.setText("Pasar turno");
        btnPasarTurno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPasarTurnoActionPerformed(evt);
            }
        });

        btnUsarObjeto.setText("Usar Objeto");
        btnUsarObjeto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUsarObjetoActionPerformed(evt);
            }
        });

        jLabel3.setText("HP Personaje: "+pers.hp+"/"+pers.hp_max);

        jLabel4.setText("HP Rival: "+rival.hp+"/"+rival.hp_max);

        barraPers.setMaximum(pers.hp_max);
        barraPers.setValue(pers.hp);

        barraRiv.setMaximum(rival.hp_max);
        barraRiv.setValue(rival.hp);

        cajaInfoPers.setEditable(false);
        cajaInfoPers.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        cajaInfoRiv.setEditable(false);
        cajaInfoRiv.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        cajaRes.setEditable(false);
        cajaRes.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        cajaRes.setText("Resultado");

        jLabel5.setText("                         ");

        jLabel6.setText("                      ");

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

        checkboxCont.setEnabled(false);

        if (pers.atc1 == 0){
            listAtcEsp.setModel(new javax.swing.DefaultComboBoxModel(new String[] { ". Ataque Especial ."}));
        }
        else if (pers.atc1 == 1){
            listAtcEsp.setModel(new javax.swing.DefaultComboBoxModel(new String[] { ". Ataque Especial .","1. "+pers.atc1_nom}));
        }
        else if (pers.atc2 == 1){
            listAtcEsp.setModel(new javax.swing.DefaultComboBoxModel(new String[] { ". Ataque Especial .","1. "+pers.atc1_nom,"2. "+pers.atc2_nom}));
        }
        else if (pers.atc3 == 1){
            listAtcEsp.setModel(new javax.swing.DefaultComboBoxModel(new String[] { ". Ataque Especial .","1. "+pers.atc1_nom,"2. "+pers.atc2_nom,"3. "+pers.atc3_nom }));
        }
        listAtcEsp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                listAtcEspActionPerformed(evt);
            }
        });

        btnEjecutar.setText("Ejecutar");
        btnEjecutar.setEnabled(false);
        btnEjecutar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEjecutarActionPerformed(evt);
            }
        });

        btnEnv.setVisible(false);
        btnEnv.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/Estados/envenenado.png"))); // NOI18N
        btnEnv.setBorder(null);
        btnEnv.setContentAreaFilled(false);

        btnQue.setVisible(false);
        btnQue.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/Estados/quemado.png"))); // NOI18N
        btnQue.setBorder(null);
        btnQue.setOpaque(false);

        btnCon.setVisible(false);
        btnCon.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/Estados/congelado.png"))); // NOI18N
        btnCon.setBorder(null);
        btnCon.setOpaque(false);

        btnPar.setVisible(false);
        btnPar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/Estados/paralizado.png"))); // NOI18N
        btnPar.setBorder(null);
        btnPar.setOpaque(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(39, 39, 39)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel5))
                        .addGap(225, 225, 225))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap(46, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(cajaRes, javax.swing.GroupLayout.PREFERRED_SIZE, 321, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(checkboxCont))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnContinuar))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(35, 35, 35)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(btnAtacar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(btnDefender, javax.swing.GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE)
                                            .addComponent(btnPasarTurno, javax.swing.GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE)
                                            .addComponent(btnUsarObjeto, javax.swing.GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE)
                                            .addComponent(btnEjecutar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE)
                                            .addComponent(listAtcEsp, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                .addGap(28, 28, 28)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel4)
                                    .addComponent(barraRiv, javax.swing.GroupLayout.DEFAULT_SIZE, 259, Short.MAX_VALUE)
                                    .addComponent(jLabel3)
                                    .addComponent(barraPers, javax.swing.GroupLayout.DEFAULT_SIZE, 259, Short.MAX_VALUE)
                                    .addComponent(cajaInfoPers, javax.swing.GroupLayout.DEFAULT_SIZE, 259, Short.MAX_VALUE)
                                    .addComponent(cajaInfoRiv, javax.swing.GroupLayout.DEFAULT_SIZE, 259, Short.MAX_VALUE)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(btnEnv, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(btnQue)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(btnCon)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(btnPar))))
                            .addComponent(jLabel2)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 442, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAtacar)
                    .addComponent(cajaInfoPers, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnDefender, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(cajaInfoRiv, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(6, 6, 6)))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnPasarTurno)
                        .addGap(6, 6, 6)
                        .addComponent(btnUsarObjeto))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(4, 4, 4)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(barraPers, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(20, 20, 20)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(listAtcEsp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnEjecutar)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(barraRiv, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(btnQue, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnEnv, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnCon)
                            .addComponent(btnPar))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
                .addComponent(cajaRes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGap(53, 53, 53)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnContinuar)
                            .addComponent(checkboxCont))
                        .addContainerGap())
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel6)
                        .addContainerGap())))
        );

        btnAtacar.getAccessibleContext().setAccessibleName("btnAtacar");
        btnDefender.getAccessibleContext().setAccessibleName("btnDefender");
        btnPasarTurno.getAccessibleContext().setAccessibleName("btnPasar turno");
        btnUsarObjeto.getAccessibleContext().setAccessibleName("btnUsar Objeto");
        btnContinuar.getAccessibleContext().setAccessibleName("btnContinuar");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

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

    private void btnAtacarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAtacarActionPerformed
if ((pers.hp > 0) && (rival.hp > 0)){
dolor = rival.hp - rival.Defensa(pers.Atacar());
dolor2 = pers.hp - pers.Defensa(rival.Atacar());
barraPers.setValue(pers.hp);
barraRiv.setValue(rival.hp);
cajaInfoPers.setText("Daño realizado: "+dolor);
if (rival.envenenado == true){
    btnEnv.setVisible(true);
    double hp = rival.hp * 0.9;
    rival.hp = (int)hp;
    Random rand = new Random();
    int salir = rand.nextInt(6);
    if (salir == 1){
        rival.envenenado = false;
         btnEnv.setVisible(false);
    }
}
if (rival.quemado == true){
    btnQue.setVisible(true);
    double hp = rival.hp * 0.9;
    rival.hp = (int)hp;
    Random rand = new Random();
    int salir = rand.nextInt(6);
    if (salir == 1){
        rival.quemado = false;
         btnQue.setVisible(false);
    }
}
if (rival.paralizado == true){
    cajaInfoRiv.setText("El rival está paralizado");
    btnPar.setVisible(true);
    Random rand = new Random();
    int salir = rand.nextInt(6);
    if (salir == 1){
        rival.paralizado = false;
        btnPar.setVisible(false);
    }
}
if (rival.congelado == true){
    cajaInfoRiv.setText("El rival está congelado");
    btnCon.setVisible(true);
    Random rand = new Random();
    int salir = rand.nextInt(6);
    if (salir == 1){
        rival.congelado = false;
        btnCon.setVisible(false);
    }
}
else {
cajaInfoRiv.setText("Daño recibido: "+dolor2);
}
jLabel3.setText("HP Personaje: "+pers.hp+"/"+pers.hp_max);
jLabel4.setText("HP Rival: "+rival.hp+"/"+rival.hp_max);
dolor = 0;
dolor2 = 0; //TODO add your handling code here:
}
if ((rival.hp <= 0) && (fin == false)){
    cajaRes.setText("Has vencido al rival. Continua tu aventura.");
    jLabel5.setText("Experiencia ganada: "+rival.expG);
    jLabel6.setText("Dinero obtenido: "+rival.dineroG);
    pers.exp = pers.exp + rival.expG;
    pers.dinero = pers.dinero + rival.dineroG;
    checkboxCont.setSelected(rootPaneCheckingEnabled);
    fin = true;
}
if ((pers.hp <= 0) && (fin == false)){
    cajaRes.setText("Lamentablemente has muerto, vuelve a comenzar.");
    jLabel5.setText("Experiencia ganada: 0");
    jLabel6.setText("Has perdido la mitad de tu dinero");
    pers.dinero = pers.dinero / 2;
    checkboxCont.setSelected(rootPaneCheckingEnabled);
    fin = true;
}
    }//GEN-LAST:event_btnAtacarActionPerformed

    private void btnDefenderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDefenderActionPerformed
if ((pers.hp > 0) && (rival.hp > 0)){
dolor = rival.hp - rival.Defensa(pers.Atacar()/2);
dolor2 = pers.hp - pers.Defensa(rival.Atacar()/2);
barraPers.setValue(pers.hp);
barraRiv.setValue(rival.hp);
cajaInfoPers.setText("Daño realizado: "+dolor);
if (rival.envenenado == true){
    btnEnv.setVisible(true);
    double hp = rival.hp * 0.9;
    rival.hp = (int)hp;
    Random rand = new Random();
    int salir = rand.nextInt(6);
    if (salir == 1){
        rival.envenenado = false;
         btnEnv.setVisible(false);
    }
}
if (rival.quemado == true){
    btnQue.setVisible(true);
    double hp = rival.hp * 0.9;
    rival.hp = (int)hp;
    Random rand = new Random();
    int salir = rand.nextInt(6);
    if (salir == 1){
        rival.quemado = false;
         btnQue.setVisible(false);
    }
}
if (rival.paralizado == true){
    cajaInfoRiv.setText("El rival está paralizado");
    btnPar.setVisible(true);
    Random rand = new Random();
    int salir = rand.nextInt(6);
    if (salir == 1){
        rival.paralizado = false;
        btnPar.setVisible(false);
    }
}
if (rival.congelado == true){
    cajaInfoRiv.setText("El rival está congelado");
    btnCon.setVisible(true);
    Random rand = new Random();
    int salir = rand.nextInt(6);
    if (salir == 1){
        rival.congelado = false;
        btnCon.setVisible(false);
    }
}
else {
cajaInfoRiv.setText("Daño recibido: "+dolor2);
}
jLabel3.setText("HP Personaje: "+pers.hp+"/"+pers.hp_max);
jLabel4.setText("HP Rival: "+rival.hp+"/"+rival.hp_max);
dolor = 0;
dolor2 = 0;
}
if ((rival.hp <= 0) && (fin == false)){
    cajaRes.setText("Has vencido al rival. Continua tu aventura.");
    jLabel5.setText("Experiencia ganada: "+rival.expG);
    jLabel6.setText("Dinero obtenido: "+rival.dineroG);
    pers.exp = pers.exp + rival.expG;
    pers.dinero = pers.dinero + rival.dineroG;
    checkboxCont.setSelected(rootPaneCheckingEnabled);
    fin = true;
}
if ((pers.hp <= 0) && (fin == false)){
    cajaRes.setText("Lamentablemente has muerto, vuelve a comenzar.");
    jLabel5.setText("Experiencia ganada: 0");
    jLabel6.setText("Has perdido la mitad de tu dinero");
    pers.dinero = pers.dinero / 2;
    checkboxCont.setSelected(rootPaneCheckingEnabled);
    fin = true;
}// TODO add your handling code here:
    }//GEN-LAST:event_btnDefenderActionPerformed

    private void btnPasarTurnoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPasarTurnoActionPerformed
if ((pers.hp > 0) && (rival.hp > 0)){
dolor2 = pers.hp - pers.Defensa(rival.Atacar());
barraPers.setValue(pers.hp);
barraRiv.setValue(rival.hp);
cajaInfoPers.setText("Daño realizado: 0");
if (rival.envenenado == true){
    btnEnv.setVisible(true);
    double hp = rival.hp * 0.9;
    rival.hp = (int)hp;
    Random rand = new Random();
    int salir = rand.nextInt(6);
    if (salir == 1){
        rival.envenenado = false;
         btnEnv.setVisible(false);
    }
}
if (rival.quemado == true){
    btnQue.setVisible(true);
    double hp = rival.hp * 0.9;
    rival.hp = (int)hp;
    Random rand = new Random();
    int salir = rand.nextInt(6);
    if (salir == 1){
        rival.quemado = false;
         btnQue.setVisible(false);
    }
}
if (rival.paralizado == true){
    cajaInfoRiv.setText("El rival está paralizado");
    btnPar.setVisible(true);
    Random rand = new Random();
    int salir = rand.nextInt(6);
    if (salir == 1){
        rival.paralizado = false;
        btnPar.setVisible(false);
    }
}
if (rival.congelado == true){
    cajaInfoRiv.setText("El rival está congelado");
    btnCon.setVisible(true);
    Random rand = new Random();
    int salir = rand.nextInt(6);
    if (salir == 1){
        rival.congelado = false;
        btnCon.setVisible(false);
    }
}
else {
cajaInfoRiv.setText("Daño recibido: "+dolor2);
}
jLabel3.setText("HP Personaje: "+pers.hp+"/"+pers.hp_max);
jLabel4.setText("HP Rival: "+rival.hp+"/"+rival.hp_max);
dolor = 0;
dolor2 = 0;
// TODO add your handling code here:
}
if ((rival.hp <= 0) && (fin == false)){
    cajaRes.setText("Has vencido al rival. Continua tu aventura.");
    jLabel5.setText("Experiencia ganada: "+rival.expG);
    jLabel6.setText("Dinero obtenido: "+rival.dineroG);
    pers.exp = pers.exp + rival.expG;
    pers.dinero = pers.dinero + rival.dineroG;
    checkboxCont.setSelected(rootPaneCheckingEnabled);
    fin = true;
}
if ((pers.hp <= 0) && (fin == false)){
    cajaRes.setText("Lamentablemente has muerto, vuelve a comenzar.");
    jLabel5.setText("Experiencia ganada: 0");
    jLabel6.setText("Has perdido la mitad de tu dinero");
    pers.dinero = pers.dinero / 2;
    checkboxCont.setSelected(rootPaneCheckingEnabled);
    fin = true;
}
    }//GEN-LAST:event_btnPasarTurnoActionPerformed

    private void btnContinuarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnContinuarActionPerformed
        if ((checkboxCont.isSelected() == true) && (pers.exp >= (50*pers.nivel))){
        this.hide();
        new SubNivel().setVisible(true);
        }
        else if ((checkboxCont.isSelected() == false)){
        }
        else {
            this.hide();
            switch (pers.posicion){
               case 1: new villa1.NMenu().setVisible(true); break;
               case 2: new villa2.NMenu().setVisible(true); break;
           }
        }// TODO add your handling code here:
    }//GEN-LAST:event_btnContinuarActionPerformed

    private void btnUsarObjetoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUsarObjetoActionPerformed
       if (fin == false) {
           this.hide();
        new UsObjBat().setVisible(true);
       }// TODO add your handling code here:
    }//GEN-LAST:event_btnUsarObjetoActionPerformed

    private void listAtcEspActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_listAtcEspActionPerformed
if (listAtcEsp.getSelectedIndex() == 0){
        btnEjecutar.setEnabled (false);
}   
else if (listAtcEsp.getSelectedIndex() == 1){
        cajaInfoPers.setText("PP Necesario: 5");cajaInfoRiv.setText(pers.atc1_def);
}
else if (listAtcEsp.getSelectedIndex() == 2){
        cajaInfoPers.setText("PP Necesario: 10");cajaInfoRiv.setText(pers.atc2_def);
}
else if (listAtcEsp.getSelectedIndex() == 3){
        cajaInfoPers.setText("PP Necesario: 15");cajaInfoRiv.setText(pers.atc3_def);
}// TODO add y
    }//GEN-LAST:event_listAtcEspActionPerformed

    private void btnEjecutarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEjecutarActionPerformed
if ((pers.hp > 0) && (rival.hp > 0)){
switch (listAtcEsp.getSelectedIndex()){
    case 1: switch (pers.tipo){case 1: Elfo elf = new Elfo(); dolor = rival.hp - rival.Defensa(elf.Atc1(pers)); dolor2 = pers.hp - pers.Defensa(rival.Atacar());break;
                               case 2: Mago mag = new Mago(); dolor = rival.hp - rival.Defensa(mag.Atc1(pers,rival)); dolor2 = pers.hp - pers.Defensa(rival.Atacar());break;
                               case 3: Ladron lad = new Ladron(); dolor = rival.hp - rival.Defensa(lad.Atc1(pers,rival)); dolor2 = pers.hp - pers.Defensa(rival.Atacar());break;
                               case 4: Orco orc = new Orco(); dolor = rival.hp - rival.Defensa(orc.Atc1(pers)); dolor2 = pers.hp - pers.Defensa(rival.Atacar());break;
                               case 5: Soldado sold = new Soldado(); dolor = rival.hp - rival.Defensa(sold.Atc1(pers)); dolor2 = pers.hp - pers.Defensa(rival.Atacar());break;} break;
    case 2: switch (pers.tipo){case 1: Elfo elf = new Elfo(); dolor = rival.hp - rival.Defensa(elf.Atc2(pers,rival)); dolor2 = pers.hp - pers.Defensa(rival.Atacar());break;
                               case 2: Mago mag = new Mago(); dolor = rival.hp - rival.Defensa(mag.Atc2(pers)); dolor2 = pers.hp - pers.Defensa(rival.Atacar());break;
                               case 3: Ladron lad = new Ladron(); dolor = rival.hp - rival.Defensa(lad.Atc2(pers)); dolor2 = pers.hp - pers.Defensa(rival.Atacar());break;
                               case 4: Orco orc = new Orco(); dolor = rival.hp - rival.Defensa(orc.Atc2(pers)); dolor2 = pers.hp - pers.Defensa(rival.Atacar());break;
                               case 5: Soldado sold = new Soldado(); dolor = rival.hp - rival.Defensa(sold.Atc2(pers,rival)); dolor2 = pers.hp - pers.Defensa(rival.Atacar());break;} break;
} 
barraPers.setValue(pers.hp);
barraRiv.setValue(rival.hp);
if (pers.result == 0){
    cajaInfoPers.setText ("No tienes suficientes PP");
}
if (pers.result == 1){
cajaInfoPers.setText("Daño realizado: "+dolor);
}
if (pers.robo == true){
cajaInfoPers.setText("Dinero robado: "+pers.dinero_rob);
}
if (rival.retroceso == 1){
   cajaInfoRiv.setText("El rival retrocedió");
}
if (rival.envenenado == true){
    btnEnv.setVisible(true);
    double hp = rival.hp * 0.9;
    rival.hp = (int)hp;
    Random rand = new Random();
    int salir = rand.nextInt(6);
    if (salir == 1){
        rival.envenenado = false;
         btnEnv.setVisible(false);
    }
}
if (rival.quemado == true){
    btnQue.setVisible(true);
    double hp = rival.hp * 0.9;
    rival.hp = (int)hp;
    Random rand = new Random();
    int salir = rand.nextInt(6);
    if (salir == 1){
        rival.quemado = false;
         btnQue.setVisible(false);
    }
}
if (rival.paralizado == true){
    cajaInfoRiv.setText("El rival está paralizado");
    btnPar.setVisible(true);
    Random rand = new Random();
    int salir = rand.nextInt(6);
    if (salir == 1){
        rival.paralizado = false;
        btnPar.setVisible(false);
    }
}
if (rival.congelado == true){
    cajaInfoRiv.setText("El rival está congelado");
    btnCon.setVisible(true);
    Random rand = new Random();
    int salir = rand.nextInt(6);
    if (salir == 1){
        rival.congelado = false;
        btnCon.setVisible(false);
    }
}
else {
cajaInfoRiv.setText("Daño recibido: "+dolor2);
}
jLabel3.setText("HP Personaje: "+pers.hp+"/"+pers.hp_max);
jLabel4.setText("HP Rival: "+rival.hp+"/"+rival.hp_max);

dolor = 0;
dolor2 = 0; //TODO add your handling code here:
}
if ((rival.hp <= 0) && (fin == false)){
    cajaRes.setText("Has vencido al rival. Continua tu aventura.");
    jLabel5.setText("Experiencia ganada: "+rival.expG);
    jLabel6.setText("Dinero obtenido: "+rival.dineroG);
    pers.exp = pers.exp + rival.expG;
    pers.dinero = pers.dinero + rival.dineroG;
    checkboxCont.setSelected(rootPaneCheckingEnabled);
    fin = true;
}
if ((pers.hp <= 0) && (fin == false)){
    cajaRes.setText("Lamentablemente has muerto, vuelve a comenzar.");
    jLabel5.setText("Experiencia ganada: 0");
    jLabel6.setText("Has perdido la mitad de tu dinero");
    pers.dinero = pers.dinero / 2;
    checkboxCont.setSelected(rootPaneCheckingEnabled);
    fin = true;
}// TODO add your handling code here:
    }//GEN-LAST:event_btnEjecutarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JProgressBar barraPers;
    private javax.swing.JProgressBar barraRiv;
    private javax.swing.JButton btnAtacar;
    private javax.swing.JButton btnCon;
    private javax.swing.JButton btnContinuar;
    private javax.swing.JButton btnDefender;
    private javax.swing.JButton btnEjecutar;
    private javax.swing.JButton btnEnv;
    private javax.swing.JButton btnPar;
    private javax.swing.JButton btnPasarTurno;
    private javax.swing.JButton btnQue;
    private javax.swing.JButton btnUsarObjeto;
    private javax.swing.JTextField cajaInfoPers;
    private javax.swing.JTextField cajaInfoRiv;
    private javax.swing.JTextField cajaRes;
    private javax.swing.JCheckBox checkboxCont;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JComboBox listAtcEsp;
    // End of variables declaration//GEN-END:variables

}
