package villa2;
import Globales.*;
import Personajes.*;
import java.io.*;

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

/**
 *
 * @author Xabier
 */
public class NMenu extends Inicio{

    /** Creates new form Cargar */
    public NMenu() {
        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();
        labelMenu = new javax.swing.JLabel();
        btnCampodeBatalla = new javax.swing.JButton();
        btnGuardarPartida = new javax.swing.JButton();
        btnTiendas = new javax.swing.JButton();
        btnDatos = new javax.swing.JButton();
        btnSalirGuardando = new javax.swing.JButton();
        btnSalirSinGuardar = new javax.swing.JButton();
        textGuardar = new javax.swing.JTextField();
        btnPueblos = new javax.swing.JButton();
        labelVilla2 = new javax.swing.JLabel();
        btnTaberna = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("RpG Java - Menú Principal");

        labelMenu.setFont(new java.awt.Font("Tahoma", 2, 24)); // NOI18N
        labelMenu.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        labelMenu.setText(". Menú Principal .");

        btnCampodeBatalla.setText("Campo de Batalla");
        btnCampodeBatalla.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCampodeBatallaActionPerformed(evt);
            }
        });

        btnGuardarPartida.setText("Guardar Partida");
        btnGuardarPartida.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarPartidaActionPerformed(evt);
            }
        });

        btnTiendas.setText("Tiendas");
        btnTiendas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTiendasActionPerformed(evt);
            }
        });

        btnDatos.setText("Datos");
        btnDatos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDatosActionPerformed(evt);
            }
        });

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

        btnSalirSinGuardar.setText("Salir sin guardar");
        btnSalirSinGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalirSinGuardarActionPerformed(evt);
            }
        });

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

        btnPueblos.setText("Pueblos");
        btnPueblos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPueblosActionPerformed(evt);
            }
        });

        labelVilla2.setText("Villa 2");

        btnTaberna.setText("Taberna [En construccion]");

        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()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(textGuardar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 235, Short.MAX_VALUE)
                            .addComponent(btnGuardarPartida, javax.swing.GroupLayout.DEFAULT_SIZE, 235, Short.MAX_VALUE)
                            .addComponent(btnSalirSinGuardar, javax.swing.GroupLayout.DEFAULT_SIZE, 235, Short.MAX_VALUE)
                            .addComponent(btnSalirGuardando, javax.swing.GroupLayout.DEFAULT_SIZE, 235, Short.MAX_VALUE)
                            .addComponent(btnTiendas, javax.swing.GroupLayout.DEFAULT_SIZE, 235, Short.MAX_VALUE)
                            .addComponent(btnCampodeBatalla, javax.swing.GroupLayout.DEFAULT_SIZE, 235, Short.MAX_VALUE)
                            .addComponent(labelMenu, javax.swing.GroupLayout.DEFAULT_SIZE, 235, Short.MAX_VALUE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(112, 112, 112)
                        .addComponent(labelVilla2))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(btnDatos, javax.swing.GroupLayout.DEFAULT_SIZE, 235, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(btnPueblos, javax.swing.GroupLayout.DEFAULT_SIZE, 235, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(btnTaberna, javax.swing.GroupLayout.DEFAULT_SIZE, 235, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelMenu)
                .addGap(7, 7, 7)
                .addComponent(labelVilla2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnCampodeBatalla)
                .addGap(19, 19, 19)
                .addComponent(btnGuardarPartida)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(textGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btnTiendas)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnDatos)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnPueblos)
                .addGap(18, 18, 18)
                .addComponent(btnTaberna)
                .addGap(13, 13, 13)
                .addComponent(btnSalirGuardando)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnSalirSinGuardar)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        btnCampodeBatalla.getAccessibleContext().setAccessibleName("btnCampo de Batalla");
        btnGuardarPartida.getAccessibleContext().setAccessibleName("btnGuardar Partida");
        btnTiendas.getAccessibleContext().setAccessibleName("btnTiendas");
        btnDatos.getAccessibleContext().setAccessibleName("btnDatos");
        btnSalirGuardando.getAccessibleContext().setAccessibleName("btnSalir guardando");
        btnSalirSinGuardar.getAccessibleContext().setAccessibleName("btnSalir sin guardar");
        textGuardar.getAccessibleContext().setAccessibleName("txtGuardarExito");

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

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

    private void btnDatosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDatosActionPerformed
        this.hide();
        new Datos().setVisible(true);        // TODO add your handling code here:
    }//GEN-LAST:event_btnDatosActionPerformed

    private void btnGuardarPartidaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarPartidaActionPerformed
        try{
              		FileWriter out = new FileWriter(new File("v01.txt"));//Guarda el archivo en la carpeta classes
			out.write(pers.hp);//Escribe el hp del personaje en el archivo
			out.write(pers.hp_max);
			out.write(pers.pp);
			out.write(pers.pp_max);
			out.write(pers.nivel);
			out.write(pers.exp);
			out.write(pers.dinero);
			out.write(pers.atc);
			out.write(pers.def);
			out.write(pers.suerte);
                        out.write(pers.tipo);
                        out.write(pers.atc1);
                        out.write(pers.atc2);
			out.write(pers.agilidad);
			out.write(pers.contObj1);
			out.write(pers.contObj2);
			out.write(pers.contObj3);
			out.write(pers.cC1);
			out.write(pers.cC2);
			out.write(pers.cC3);
			out.write(pers.cE1);
			out.write(pers.cE2);
			out.write(pers.cE3);
			out.close();//Cierra el flujo de datos , muy importante
                        textGuardar.setText("Personaje guardado sin problemas");
    	}catch (Exception ex){
    		textGuardar.setText(ex.getMessage());
    		}        // TODO add your handling code here:
    }//GEN-LAST:event_btnGuardarPartidaActionPerformed

    private void btnTiendasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTiendasActionPerformed
        this.hide();
        new villa2.Tiendas().setVisible(true);        // TODO add your handling code here:
    }//GEN-LAST:event_btnTiendasActionPerformed

    private void btnCampodeBatallaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCampodeBatallaActionPerformed
        this.hide();
        new villa2.ElecMons().setVisible(true);        // TODO add your handling code here:
    }//GEN-LAST:event_btnCampodeBatallaActionPerformed

    private void btnSalirGuardandoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalirGuardandoActionPerformed
  try{
              		FileWriter out = new FileWriter(new File("v01.txt"));//Guarda el archivo en la carpeta classes
			out.write(pers.hp);//Escribe el hp del personaje en el archivo
			out.write(pers.hp_max);
			out.write(pers.pp);
			out.write(pers.pp_max);
			out.write(pers.nivel);
			out.write(pers.exp);
			out.write(pers.dinero);
			out.write(pers.atc);
			out.write(pers.def);
			out.write(pers.suerte);
                        out.write(pers.tipo);
                        out.write(pers.atc1);
                        out.write(pers.atc2);
			out.write(pers.agilidad);
			out.write(pers.contObj1);
			out.write(pers.contObj2);
			out.write(pers.contObj3);
			out.write(pers.cC1);
			out.write(pers.cC2);
			out.write(pers.cC3);
			out.write(pers.cE1);
			out.write(pers.cE2);
			out.write(pers.cE3);
			out.close();//Cierra el flujo de datos , muy importante
                        textGuardar.setText("Personaje guardado sin problemas");
    	}catch (Exception ex){
    		textGuardar.setText(ex.getMessage());
    		}
  System.exit(0);       // TODO add your handling code here:
    }//GEN-LAST:event_btnSalirGuardandoActionPerformed

    private void btnSalirSinGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalirSinGuardarActionPerformed
 System.exit(0);         // TODO add your handling code here:
    }//GEN-LAST:event_btnSalirSinGuardarActionPerformed

    private void btnPueblosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPueblosActionPerformed
this.hide();
        new VisitVillas().setVisible(true);        // TODO add your handling code here:
    }//GEN-LAST:event_btnPueblosActionPerformed
 

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCampodeBatalla;
    private javax.swing.JButton btnDatos;
    private javax.swing.JButton btnGuardarPartida;
    private javax.swing.JButton btnPueblos;
    private javax.swing.JButton btnSalirGuardando;
    private javax.swing.JButton btnSalirSinGuardar;
    private javax.swing.JButton btnTaberna;
    private javax.swing.JButton btnTiendas;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel labelMenu;
    private javax.swing.JLabel labelVilla2;
    private javax.swing.JTextField textGuardar;
    // End of variables declaration//GEN-END:variables

}
