package UhuRisk;

/*
 * fTablero.java
 *
 * Created on 9 de enero de 2009, 15:04
 */
import java.awt.Color;
import java.util.ArrayList;
import java.util.Observer;
import java.util.Observable;
import javax.swing.JOptionPane;


/**
 *
 * @author  juan antonio
 */
public class fTablero extends javax.swing.JFrame implements Observer{

    private ArrayList<Territorio> lterritorios;
    
    private Territorio terAtacante;
    
    private Territorio terDefensor;
    
    private Territorio terOrigen;
    
    private Territorio terDestino;
    
    private boolean primeraPulsacion;
    
    private fPartida fp;
    
    private ArrayList<javax.swing.JLabel> listalabels;
    
    private Partida miPartida;
    /** Creates new form fTablero */
    
    MP3 mp3 = new MP3("/BSO Piratas del Caribe - He'S A Pirate.mp3");
    
    public fTablero(Partida p, fPartida f) {
        initComponents();
        miPartida=p;
        fp=f;
        listalabels=new ArrayList();
        lterritorios=new ArrayList();
        lterritorios=miPartida.getTerritorio();
        this.mp3.play();
        listalabels.add(lt1);
        listalabels.add(lt2);
        listalabels.add(lt3);
        listalabels.add(lt4);
        listalabels.add(lt5);
        listalabels.add(lt6);
        listalabels.add(lt7);
        listalabels.add(lt8);
        listalabels.add(lt9);
        listalabels.add(lt10);
        listalabels.add(lt11);
        listalabels.add(lt12);
        listalabels.add(lt13);
        listalabels.add(lt14);
        listalabels.add(lt15);
        listalabels.add(lt16);
        listalabels.add(lt17);
        listalabels.add(lt18);
        listalabels.add(lt19);
        listalabels.add(lt20);
        listalabels.add(lt21);
        listalabels.add(lt22);
        listalabels.add(lt23);
        listalabels.add(lt24);
        listalabels.add(lt25);
        listalabels.add(lt26);
        listalabels.add(lt27);
        listalabels.add(lt28);
        listalabels.add(lt29);
        listalabels.add(lt30);
        listalabels.add(lt31);
        listalabels.add(lt32);
        listalabels.add(lt33);
        listalabels.add(lt34);
        listalabels.add(lt35);
        listalabels.add(lt36);
        listalabels.add(lt37);
        listalabels.add(lt38);
        listalabels.add(lt39);
        listalabels.add(lt40);
        listalabels.add(lt41);
        listalabels.add(lt42);
        listalabels.add(lt43);
        listalabels.add(lt44);
        listalabels.add(lt45);
        lpbotones.setVisible(false);
        bcomenzar.setVisible(false);
        laccion.setVisible(false);   
        lptablero.setVisible(true);
        bcontinuar.setVisible(false);
        babandonar.setVisible(false);
        lnumejercitos.setVisible(false);
        snumEjercitos.setVisible(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() {

        lptablero = new javax.swing.JLayeredPane();
        lt1 = new javax.swing.JLabel();
        lt31 = new javax.swing.JLabel();
        lt3 = new javax.swing.JLabel();
        lt4 = new javax.swing.JLabel();
        lt2 = new javax.swing.JLabel();
        lt5 = new javax.swing.JLabel();
        lt6 = new javax.swing.JLabel();
        lt29 = new javax.swing.JLabel();
        lt33 = new javax.swing.JLabel();
        lt34 = new javax.swing.JLabel();
        lt44 = new javax.swing.JLabel();
        lt45 = new javax.swing.JLabel();
        lt43 = new javax.swing.JLabel();
        lt32 = new javax.swing.JLabel();
        lt39 = new javax.swing.JLabel();
        lt40 = new javax.swing.JLabel();
        lt41 = new javax.swing.JLabel();
        lt42 = new javax.swing.JLabel();
        lt38 = new javax.swing.JLabel();
        lt37 = new javax.swing.JLabel();
        lt36 = new javax.swing.JLabel();
        lt35 = new javax.swing.JLabel();
        lt7 = new javax.swing.JLabel();
        lt9 = new javax.swing.JLabel();
        lt8 = new javax.swing.JLabel();
        lt10 = new javax.swing.JLabel();
        lt11 = new javax.swing.JLabel();
        lt12 = new javax.swing.JLabel();
        lt13 = new javax.swing.JLabel();
        lt14 = new javax.swing.JLabel();
        lt15 = new javax.swing.JLabel();
        lt16 = new javax.swing.JLabel();
        lt17 = new javax.swing.JLabel();
        lt18 = new javax.swing.JLabel();
        lt19 = new javax.swing.JLabel();
        lt20 = new javax.swing.JLabel();
        lt21 = new javax.swing.JLabel();
        lt23 = new javax.swing.JLabel();
        lt22 = new javax.swing.JLabel();
        lt26 = new javax.swing.JLabel();
        lt27 = new javax.swing.JLabel();
        lt25 = new javax.swing.JLabel();
        lt28 = new javax.swing.JLabel();
        lt24 = new javax.swing.JLabel();
        lt30 = new javax.swing.JLabel();
        lpanel = new javax.swing.JLabel();
        lpbotones = new javax.swing.JLayeredPane();
        btransferir = new javax.swing.JButton();
        bguardar = new javax.swing.JButton();
        bcargar = new javax.swing.JButton();
        lejercitos = new javax.swing.JLabel();
        bterminarAtaques = new javax.swing.JButton();
        lronda = new javax.swing.JLabel();
        ljugador = new javax.swing.JLabel();
        babandonar = new javax.swing.JButton();
        batacar = new javax.swing.JButton();
        bcartas = new javax.swing.JButton();
        bfinalizar = new javax.swing.JButton();
        basignar = new javax.swing.JButton();
        bcomenzar = new javax.swing.JButton();
        laccion = new javax.swing.JLabel();
        bcontinuar = new javax.swing.JButton();
        lnumejercitos = new javax.swing.JLabel();
        snumEjercitos = new javax.swing.JSlider();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        lt1.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt1.setOpaque(true);
        lt1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt1.setBounds(40, 40, 20, 20);
        lptablero.add(lt1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt31.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt31.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt31.setOpaque(true);
        lt31.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt31.setBounds(400, 210, 20, 20);
        lptablero.add(lt31, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt3.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt3.setOpaque(true);
        lt3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt3.setBounds(90, 60, 20, 20);
        lptablero.add(lt3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt4.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt4.setOpaque(true);
        lt4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt4.setBounds(110, 110, 20, 20);
        lptablero.add(lt4, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt2.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt2.setOpaque(true);
        lt2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt2.setBounds(54, 90, 20, 20);
        lptablero.add(lt2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt5.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt5.setOpaque(true);
        lt5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt5.setBounds(140, 60, 20, 20);
        lptablero.add(lt5, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt6.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt6.setOpaque(true);
        lt6.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt6.setBounds(170, 90, 20, 20);
        lptablero.add(lt6, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt29.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt29.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt29.setOpaque(true);
        lt29.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt29.setBounds(290, 180, 20, 20);
        lptablero.add(lt29, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt33.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt33.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt33.setOpaque(true);
        lt33.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt33.setBounds(340, 230, 20, 20);
        lptablero.add(lt33, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt34.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt34.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt34.setOpaque(true);
        lt34.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt34.setBounds(460, 230, 20, 20);
        lptablero.add(lt34, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt44.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt44.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt44.setOpaque(true);
        lt44.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt44.setBounds(520, 140, 20, 20);
        lptablero.add(lt44, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt45.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt45.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt45.setOpaque(true);
        lt45.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt45.setBounds(540, 180, 20, 20);
        lptablero.add(lt45, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt43.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt43.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt43.setOpaque(true);
        lt43.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt43.setBounds(490, 160, 20, 20);
        lptablero.add(lt43, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt32.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt32.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt32.setOpaque(true);
        lt32.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt32.setBounds(350, 280, 20, 20);
        lptablero.add(lt32, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt39.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt39.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt39.setOpaque(true);
        lt39.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt39.setBounds(400, 300, 20, 20);
        lptablero.add(lt39, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt40.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt40.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt40.setOpaque(true);
        lt40.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt40.setBounds(450, 280, 20, 20);
        lptablero.add(lt40, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt41.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt41.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt41.setOpaque(true);
        lt41.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt41.setBounds(490, 340, 20, 20);
        lptablero.add(lt41, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt42.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt42.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt42.setOpaque(true);
        lt42.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt42.setBounds(550, 390, 20, 20);
        lptablero.add(lt42, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt38.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt38.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt38.setOpaque(true);
        lt38.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt38.setBounds(430, 340, 20, 20);
        lptablero.add(lt38, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt37.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt37.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt37.setOpaque(true);
        lt37.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt37.setBounds(390, 340, 20, 20);
        lptablero.add(lt37, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt36.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt36.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt36.setOpaque(true);
        lt36.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt36.setBounds(290, 380, 20, 20);
        lptablero.add(lt36, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt35.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt35.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt35.setOpaque(true);
        lt35.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt35.setBounds(320, 350, 20, 20);
        lptablero.add(lt35, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt7.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt7.setOpaque(true);
        lt7.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt7.setBounds(30, 460, 20, 20);
        lptablero.add(lt7, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt9.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt9.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt9.setOpaque(true);
        lt9.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt9.setBounds(90, 480, 20, 20);
        lptablero.add(lt9, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt8.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt8.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt8.setOpaque(true);
        lt8.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt8.setBounds(60, 500, 20, 20);
        lptablero.add(lt8, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt10.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt10.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt10.setOpaque(true);
        lt10.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt10.setBounds(130, 510, 20, 20);
        lptablero.add(lt10, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt11.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt11.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt11.setOpaque(true);
        lt11.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt11.setBounds(110, 540, 20, 20);
        lptablero.add(lt11, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt12.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt12.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt12.setOpaque(true);
        lt12.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt12.setBounds(140, 570, 20, 20);
        lptablero.add(lt12, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt13.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt13.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt13.setOpaque(true);
        lt13.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt13.setBounds(320, 500, 20, 20);
        lptablero.add(lt13, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt14.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt14.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt14.setOpaque(true);
        lt14.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt14.setBounds(360, 490, 20, 20);
        lptablero.add(lt14, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt15.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt15.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt15.setOpaque(true);
        lt15.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt15.setBounds(370, 520, 20, 20);
        lptablero.add(lt15, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt16.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt16.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt16.setOpaque(true);
        lt16.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt16.setBounds(420, 510, 20, 20);
        lptablero.add(lt16, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt17.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt17.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt17.setOpaque(true);
        lt17.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt17.setBounds(410, 560, 20, 20);
        lptablero.add(lt17, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt18.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt18.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt18.setOpaque(true);
        lt18.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt18.setBounds(450, 550, 20, 20);
        lptablero.add(lt18, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt19.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt19.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt19.setOpaque(true);
        lt19.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt19.setBounds(450, 590, 20, 20);
        lptablero.add(lt19, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt20.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt20.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt20.setOpaque(true);
        lt20.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt20.setBounds(610, 550, 20, 20);
        lptablero.add(lt20, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt21.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt21.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt21.setOpaque(true);
        lt21.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt21.setBounds(630, 480, 20, 20);
        lptablero.add(lt21, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt23.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt23.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt23.setOpaque(true);
        lt23.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt23.setBounds(700, 530, 20, 20);
        lptablero.add(lt23, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt22.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt22.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt22.setOpaque(true);
        lt22.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt22.setBounds(650, 540, 20, 20);
        lptablero.add(lt22, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt26.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt26.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt26.setOpaque(true);
        lt26.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt26.setBounds(740, 510, 20, 20);
        lptablero.add(lt26, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt27.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt27.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt27.setOpaque(true);
        lt27.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt27.setBounds(770, 490, 20, 20);
        lptablero.add(lt27, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt25.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt25.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt25.setOpaque(true);
        lt25.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt25.setBounds(720, 480, 20, 20);
        lptablero.add(lt25, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt28.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt28.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt28.setOpaque(true);
        lt28.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt28.setBounds(720, 440, 20, 20);
        lptablero.add(lt28, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt24.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt24.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt24.setOpaque(true);
        lt24.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt24.setBounds(680, 460, 20, 20);
        lptablero.add(lt24, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lt30.setFont(new java.awt.Font("Tahoma", 1, 14));
        lt30.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lt30.setOpaque(true);
        lt30.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ltMouseClicked(evt);
            }
        });
        lt30.setBounds(340, 190, 20, 20);
        lptablero.add(lt30, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lpanel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Copia de tableroFINAL1.jpg"))); // NOI18N
        lpanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(227, 121, 22), 4));
        lpanel.setBounds(10, 10, 800, 608);
        lptablero.add(lpanel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lpbotones.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 3, true));

        btransferir.setText("Transferir");
        btransferir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btransferirActionPerformed(evt);
            }
        });
        btransferir.setBounds(10, 170, 120, 23);
        lpbotones.add(btransferir, javax.swing.JLayeredPane.DEFAULT_LAYER);

        bguardar.setText("Guardar Partida");
        bguardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bguardarActionPerformed(evt);
            }
        });
        bguardar.setBounds(170, 220, 190, 23);
        lpbotones.add(bguardar, javax.swing.JLayeredPane.DEFAULT_LAYER);

        bcargar.setText("Ver Historial");
        bcargar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bcargarActionPerformed(evt);
            }
        });
        bcargar.setBounds(170, 260, 190, 23);
        lpbotones.add(bcargar, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lejercitos.setFont(new java.awt.Font("Tahoma", 1, 11));
        lejercitos.setText("Ejercitos disponibles:");
        lejercitos.setBounds(20, 60, 160, 14);
        lpbotones.add(lejercitos, javax.swing.JLayeredPane.DEFAULT_LAYER);

        bterminarAtaques.setText("Terminar ataques");
        bterminarAtaques.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bterminarAtaquesActionPerformed(evt);
            }
        });
        bterminarAtaques.setBounds(167, 120, 189, 23);
        lpbotones.add(bterminarAtaques, javax.swing.JLayeredPane.DEFAULT_LAYER);

        lronda.setFont(new java.awt.Font("Tahoma", 1, 11));
        lronda.setText("Ronda numero: ");
        lronda.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2));
        lronda.setOpaque(true);
        lronda.setBounds(12, 344, 240, 20);
        lpbotones.add(lronda, javax.swing.JLayeredPane.DEFAULT_LAYER);

        ljugador.setFont(new java.awt.Font("Tahoma", 1, 11));
        ljugador.setText("Es el turno del Jugador:");
        ljugador.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2));
        ljugador.setOpaque(true);
        ljugador.setBounds(20, 10, 240, 20);
        lpbotones.add(ljugador, javax.swing.JLayeredPane.DEFAULT_LAYER);

        babandonar.setText("Abandonar Partida");
        babandonar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                babandonarActionPerformed(evt);
            }
        });
        babandonar.setBounds(169, 170, 187, 23);
        lpbotones.add(babandonar, javax.swing.JLayeredPane.DEFAULT_LAYER);

        batacar.setText("Atacar");
        batacar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                batacarActionPerformed(evt);
            }
        });
        batacar.setBounds(10, 120, 120, 23);
        lpbotones.add(batacar, javax.swing.JLayeredPane.DEFAULT_LAYER);

        bcartas.setText("Ver Cartas");
        bcartas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bcartasActionPerformed(evt);
            }
        });
        bcartas.setBounds(10, 220, 120, 23);
        lpbotones.add(bcartas, javax.swing.JLayeredPane.DEFAULT_LAYER);

        bfinalizar.setText("Finalizar turno");
        bfinalizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bfinalizarActionPerformed(evt);
            }
        });
        bfinalizar.setBounds(13, 263, 120, 23);
        lpbotones.add(bfinalizar, javax.swing.JLayeredPane.DEFAULT_LAYER);

        basignar.setText("Asignar Territorios");
        basignar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                basignarActionPerformed(evt);
            }
        });

        bcomenzar.setText("Comenzar");
        bcomenzar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bcomenzarActionPerformed(evt);
            }
        });

        laccion.setBackground(new java.awt.Color(255, 255, 255));
        laccion.setFont(new java.awt.Font("Tahoma", 1, 18));
        laccion.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 3));
        laccion.setOpaque(true);

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

        lnumejercitos.setFont(new java.awt.Font("Tahoma", 1, 12));
        lnumejercitos.setText("Indique el numero de ejercitos para transferir:");

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

        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, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(laccion, javax.swing.GroupLayout.PREFERRED_SIZE, 1000, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(65, 65, 65)
                        .addComponent(bcontinuar, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lptablero, javax.swing.GroupLayout.PREFERRED_SIZE, 829, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(bcomenzar, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(basignar, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(123, 123, 123))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(26, 26, 26)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(snumEjercitos, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 371, Short.MAX_VALUE)
                                    .addComponent(lnumejercitos, javax.swing.GroupLayout.PREFERRED_SIZE, 345, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(lpbotones, javax.swing.GroupLayout.DEFAULT_SIZE, 371, Short.MAX_VALUE)))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(lptablero, javax.swing.GroupLayout.PREFERRED_SIZE, 633, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addComponent(basignar)
                        .addGap(28, 28, 28)
                        .addComponent(bcomenzar)
                        .addGap(18, 18, 18)
                        .addComponent(lpbotones, javax.swing.GroupLayout.PREFERRED_SIZE, 398, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(51, 51, 51)
                        .addComponent(lnumejercitos)
                        .addGap(18, 18, 18)
                        .addComponent(snumEjercitos, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 41, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(bcontinuar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(laccion, javax.swing.GroupLayout.DEFAULT_SIZE, 37, Short.MAX_VALUE))
                .addContainerGap())
        );

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

private void basignarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_basignarActionPerformed
// TODO add your handling code here:
    getMiPartida().asignarPartJug(getMiPartida());
    getMiPartida().asignarPartTer(getMiPartida());
    getMiPartida().asignarTerritorios();
    bcomenzar.setVisible(true);
    basignar.setVisible(false);
}//GEN-LAST:event_basignarActionPerformed



private void bcomenzarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bcomenzarActionPerformed
// TODO add your handling code here:
    getMiPartida().ponerActivo();
    bcomenzar.setVisible(false);
    lpbotones.setVisible(true);
    ljugador.setText("Ronda numero:"+miPartida.getNumRondaActual());
    laccion.setVisible(true);
    batacar.setVisible(false);
    bterminarAtaques.setVisible(false);
    btransferir.setVisible(false);
    bcartas.setVisible(false);
    bfinalizar.setVisible(false);
    babandonar.setVisible(false);
    lronda.setText("Es el turno del jugador: "+ getMiPartida().getJugador(getMiPartida().getJugadorActivo()).getNombre());
    lronda.setBackground(getMiPartida().getJugador(getMiPartida().getJugadorActivo()).getColor());
    lejercitos.setText("Ejercitos disponibles: "+getMiPartida().getJugador(getMiPartida().getJugadorActivo()).getNumEjercitos());
    laccion.setText("Ubique sus ejercitos, pinche sobre un territorio suyo para aumentar los ejercitos en ese territorio.");
    getMiPartida().setUbicando(true);
}//GEN-LAST:event_bcomenzarActionPerformed

private void bfinalizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bfinalizarActionPerformed
// TODO add your handling code here:
    if( getMiPartida().getJugadorActivo()==getMiPartida().getNumJugadores()){
            getMiPartida().setPrimerTurno(false);
            if(this.miPartida.isLimiteRondas()==true){
                String nom=null;
                if(this.miPartida.getNumRondaActual()==this.miPartida.getNumRondas()){
                    JOptionPane.showMessageDialog(this,"Se han acabado las rondas.");
                    int num=0;
                    int id;
                    for(id=1; id<=this.miPartida.getNumJugadores(); id++){
                        if(num<this.miPartida.getJugador(id).getnumTerritorios()){
                            num=this.miPartida.getJugador(id).getnumTerritorios();
                            nom=miPartida.getJugador(id).getNombre();
                        }
                    }
                    JOptionPane.showMessageDialog(this,"El ganador es el jugador "+nom);
                    this.fp.dispose();
                    this.dispose();
                    this.mp3.close();
                }
            }  
    }
    if(this.miPartida.terminarJuego()==true){
        JOptionPane.showMessageDialog(this,"FIN DEL JUEGO. EL GANADOR ES EL JUGADOR "+this.miPartida.getJugadores().get(this.miPartida.getJugadorActivo()).getNombre());
        this.fp.dispose();
        this.dispose();
        this.mp3.close();
    }
    else{
        miPartida.getJugador(getMiPartida().getJugadorActivo()).finalizarTurno();
        lronda.setText("Es el turno del jugador: "+ getMiPartida().getJugador(getMiPartida().getJugadorActivo()).getNombre());
        lronda.setBackground(getMiPartida().getJugador(getMiPartida().getJugadorActivo()).getColor());
        lejercitos.setText("Ejercitos disponibles: "+getMiPartida().getJugador(getMiPartida().getJugadorActivo()).getNumEjercitos());
        laccion.setText("Ubique sus ejercitos, pinche sobre un territorio suyo para aumentar los ejercitos en ese territorio.");
        ljugador.setText("Ronda numero: "+this.miPartida.getNumRondaActual());
        bfinalizar.setVisible(false);
        batacar.setVisible(false);
        bterminarAtaques.setVisible(false);
        bcartas.setVisible(false);
        btransferir.setVisible(false);
        babandonar.setVisible(false);
        miPartida.setUbicando(true);
        miPartida.setAtacando(false);
        miPartida.setTransfiriendo(false);
    }
}//GEN-LAST:event_bfinalizarActionPerformed

private void ltMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ltMouseClicked
// TODO add your handling code here:
    javax.swing.JLabel l=(javax.swing.JLabel)evt.getComponent();  //recoje en la variable l el label que lanza el evento
    int indice=listalabels.indexOf(l);
    Territorio t=lterritorios.get(indice);
    if( getMiPartida().isUbicando()==true){
        String mensaje=getMiPartida().getJugador(getMiPartida().getJugadorActivo()).ubicarEjercitos(t);
        laccion.setText(mensaje);
        lejercitos.setText("Ejercitos disponibles: "+getMiPartida().getJugador(getMiPartida().getJugadorActivo()).getNumEjercitos());
        if( getMiPartida().getJugador(getMiPartida().getJugadorActivo()).getNumEjercitos()==0){
            bcontinuar.setVisible(true);
        }    
    }
    else if(getMiPartida().isAtacando()==true){
        if(this.isPrimeraPulsacion()==false){
                this.setTerAtacante(t);
            this.setPrimeraPulsacion(true);
            laccion.setText("Va atacar desde "+this.getTerAtacante().getNomTerritorio()+". Seleccione el territorio que desee atacar.");
        }
        else{
            this.setTerDefensor(t);
            this.setPrimeraPulsacion(false);
            laccion.setText("Va a atacar a"+this.getTerDefensor().getNomTerritorio()+". Pulse atacar para comenzar el ataque.");
            boolean comp=getMiPartida().getJugador(getMiPartida().getJugadorActivo()).comprobarAtaque(getTerAtacante(), getTerDefensor());
            if(comp==false){
                JOptionPane.showMessageDialog(this,"Los territorios seleccionados no son validos para el ataque.");
                this.setPrimeraPulsacion(false);
                setTerAtacante(null);
                setTerDefensor(null);
                laccion.setText("Pulse sobre el territorio atacante.");
            }
        }
    }
    else if(miPartida.isTransfiriendo()==true){
        if(this.isPrimeraPulsacion()==false){
            this.setTerOrigen(t);
            this.setPrimeraPulsacion(true);
            laccion.setText("Va a transferir desde "+this.terOrigen.getNomTerritorio()+". Seleccione el territorio de destino.");
        } 
        else{
            this.setTerDestino(t);
            this.setPrimeraPulsacion(false);
            laccion.setText("Va a transferir a "+this.terDestino.getNomTerritorio()+". Indique el numero de ejercitos que desee transferir y pulse atacar.");
            boolean comp=getMiPartida().getJugador(getMiPartida().getJugadorActivo()).comprobarTransferencia(terOrigen, terDestino);
            if(comp==false){
                JOptionPane.showMessageDialog(this,"Los territorios seleccionados no son validos para la transferencia.");
                this.setPrimeraPulsacion(false);
                this.setTerOrigen(null);
                this.setTerDestino(null);
                laccion.setText("Pulse sobre el territorio origen de la transferencia.");
            }
            else{
                lnumejercitos.setVisible(true);
                snumEjercitos.setMinimum(1);
                snumEjercitos.setMaximum(this.terOrigen.getNumEjercitos()-1);
                snumEjercitos.setVisible(true);
                snumEjercitos.setValue(snumEjercitos.getMinimum());
            }
        }
    }
}//GEN-LAST:event_ltMouseClicked

private void bcontinuarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bcontinuarActionPerformed
// TODO add your handling code here:
    if( getMiPartida().isPrimerTurno()==true){
        if( getMiPartida().isUbicando()==true){
            bcontinuar.setVisible(false);
            bfinalizar.setVisible(true);
        }
    }
    else{
        if( getMiPartida().isUbicando()==true){
                getMiPartida().setUbicando(false);
                getMiPartida().setAtacando(true);
            this.setPrimeraPulsacion(false);
            bcontinuar.setVisible(false);
            batacar.setVisible(true);
            bterminarAtaques.setVisible(true);
            bcartas.setVisible(true);
            bfinalizar.setVisible(true); 
            babandonar.setVisible(true);
            laccion.setText("Pulse sobre el territorio atacante.");
        }
        else if(getMiPartida().isAtacando()==true){
            this.miPartida.setAtacando(false);
            getMiPartida().setUbicando(false);
            getMiPartida().setTransfiriendo(true);
            this.bcontinuar.setVisible(false);
            batacar.setVisible(false);
            bterminarAtaques.setVisible(false);
            btransferir.setVisible(true);
            bcartas.setVisible(true);
            bfinalizar.setVisible(true);
            babandonar.setVisible(true);
            laccion.setText("Pulse sobre el territorio origen de la transferencia.");
        }
        else if(this.miPartida.isTransfiriendo()==true){
            this.miPartida.setTransfiriendo(false);
            this.btransferir.setVisible(false);
            this.bcontinuar.setVisible(false);
            laccion.setText("Tiene que finalizar su turno");       
        }
    }
}//GEN-LAST:event_bcontinuarActionPerformed

private void batacarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_batacarActionPerformed
// TODO add your handling code here:
    if( getTerAtacante()==null){ 
        laccion.setText("Por favor, seleccione el territorio atacante.");
    }
    else if(getTerDefensor()==null){
        laccion.setText("Por favor, seleccione el territorio que desea atacar.");
    }
    else{
        this.setEnabled(false);
        this.mp3.close();
        fatacar fa=new fatacar(getTerAtacante(), getTerDefensor(),this.getMiPartida(), this);
        fa.setVisible(true);
    }
}//GEN-LAST:event_batacarActionPerformed


private void bterminarAtaquesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bterminarAtaquesActionPerformed
// TODO add your handling code here:
    batacar.setVisible(false);
    laccion.setText("Se han terminado los ataques. Pulse continuar.");
    this.bterminarAtaques.setVisible(false);
    bcontinuar.setVisible(true);
}//GEN-LAST:event_bterminarAtaquesActionPerformed

private void bcartasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bcartasActionPerformed
// TODO add your handling code here:
    this.setEnabled(false);
    JCartas jca=new JCartas(this);
    jca.setVisible(true);
}//GEN-LAST:event_bcartasActionPerformed


private void babandonarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_babandonarActionPerformed
// TODO add your handling code here:
    JOptionPane.showMessageDialog(this,"La partida ha sido abandonada.");
    this.getMiPartida().getJugador(this.getMiPartida().getJugadorActivo()).setJugando(false);
    this.bfinalizarActionPerformed(evt);
}//GEN-LAST:event_babandonarActionPerformed

private void btransferirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btransferirActionPerformed
// TODO add your handling code here:
    if( this.terOrigen==null){ 
        laccion.setText("Por favor, seleccione el territorio de origen.");
    }
    else if(this.terDestino==null){
        laccion.setText("Por favor, seleccione el territorio de destino.");
    }
    else{
        int num=this.snumEjercitos.getValue();
        String mensaje=this.miPartida.getJugador(this.miPartida.getJugadorActivo()).transferirEjercitos(terOrigen, terDestino, num);
        laccion.setText(mensaje);
        this.btransferir.setVisible(false);
        this.snumEjercitos.setVisible(false);
        this.lnumejercitos.setVisible(false);
        this.bcontinuar.setVisible(true);
    }
}//GEN-LAST:event_btransferirActionPerformed

private void bguardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bguardarActionPerformed
// TODO add your handling code here:
    ControladorBD.persist(miPartida);
}//GEN-LAST:event_bguardarActionPerformed

private void bcargarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bcargarActionPerformed
// TODO add your handling code here:
    this.setEnabled(false);
    fcargar ca=new fcargar(this);
    ca.setVisible(true);
}//GEN-LAST:event_bcargarActionPerformed

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

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton babandonar;
    private javax.swing.JButton basignar;
    private javax.swing.JButton batacar;
    private javax.swing.JButton bcargar;
    private javax.swing.JButton bcartas;
    private javax.swing.JButton bcomenzar;
    private javax.swing.JButton bcontinuar;
    private javax.swing.JButton bfinalizar;
    private javax.swing.JButton bguardar;
    private javax.swing.JButton bterminarAtaques;
    private javax.swing.JButton btransferir;
    private javax.swing.JLabel laccion;
    private javax.swing.JLabel lejercitos;
    private javax.swing.JLabel ljugador;
    private javax.swing.JLabel lnumejercitos;
    private javax.swing.JLabel lpanel;
    private javax.swing.JLayeredPane lpbotones;
    private javax.swing.JLayeredPane lptablero;
    private javax.swing.JLabel lronda;
    private javax.swing.JLabel lt1;
    private javax.swing.JLabel lt10;
    private javax.swing.JLabel lt11;
    private javax.swing.JLabel lt12;
    private javax.swing.JLabel lt13;
    private javax.swing.JLabel lt14;
    private javax.swing.JLabel lt15;
    private javax.swing.JLabel lt16;
    private javax.swing.JLabel lt17;
    private javax.swing.JLabel lt18;
    private javax.swing.JLabel lt19;
    private javax.swing.JLabel lt2;
    private javax.swing.JLabel lt20;
    private javax.swing.JLabel lt21;
    private javax.swing.JLabel lt22;
    private javax.swing.JLabel lt23;
    private javax.swing.JLabel lt24;
    private javax.swing.JLabel lt25;
    private javax.swing.JLabel lt26;
    private javax.swing.JLabel lt27;
    private javax.swing.JLabel lt28;
    private javax.swing.JLabel lt29;
    private javax.swing.JLabel lt3;
    private javax.swing.JLabel lt30;
    private javax.swing.JLabel lt31;
    private javax.swing.JLabel lt32;
    private javax.swing.JLabel lt33;
    private javax.swing.JLabel lt34;
    private javax.swing.JLabel lt35;
    private javax.swing.JLabel lt36;
    private javax.swing.JLabel lt37;
    private javax.swing.JLabel lt38;
    private javax.swing.JLabel lt39;
    private javax.swing.JLabel lt4;
    private javax.swing.JLabel lt40;
    private javax.swing.JLabel lt41;
    private javax.swing.JLabel lt42;
    private javax.swing.JLabel lt43;
    private javax.swing.JLabel lt44;
    private javax.swing.JLabel lt45;
    private javax.swing.JLabel lt5;
    private javax.swing.JLabel lt6;
    private javax.swing.JLabel lt7;
    private javax.swing.JLabel lt8;
    private javax.swing.JLabel lt9;
    private javax.swing.JSlider snumEjercitos;
    // End of variables declaration//GEN-END:variables

    public void update(Observable o, Object arg) {
        Territorio t=(Territorio)o;
        Color c=t.getColor();
        int num=t.getNumEjercitos();
        int id=t.getIdTerritorio();
        String n=String.valueOf(t.getNumEjercitos());
        listalabels.get(id-1).setBackground(c);
        listalabels.get(id-1).setText(n);
        if(getMiPartida().isUbicando()==true){
            lejercitos.setText("Ejercitos disponibles: "+getMiPartida().getJugador(getMiPartida().getJugadorActivo()).getNumEjercitos());
        }       
    }

    public boolean isPrimeraPulsacion() {
        return primeraPulsacion;
    }

    public void setPrimeraPulsacion(boolean primeraPulsacion) {
        this.primeraPulsacion = primeraPulsacion;
    }

    public Territorio getTerAtacante() {
        return terAtacante;
    }

    public void setTerAtacante(Territorio terAtacante) {
        this.terAtacante = terAtacante;
    }

    public Territorio getTerDefensor() {
        return terDefensor;
    }

    public void setTerDefensor(Territorio terDefensor) {
        this.terDefensor = terDefensor;
    }

    public Partida getMiPartida() {
        return miPartida;
    }

    public void setMiPartida(Partida miPartida) {
        this.miPartida = miPartida;
    }

    public Territorio getTerOrigen() {
        return terOrigen;
    }

    public void setTerOrigen(Territorio terOrigen) {
        this.terOrigen = terOrigen;
    }

    public Territorio getTerDestino() {
        return terDestino;
    }

    public void setTerDestino(Territorio terDestino) {
        this.terDestino = terDestino;
    }
    
}
