~eduardo_quiros/mainbrain

4df0fd67bd27bf1c7b259233b46435d01b502c7d — Eduardo Quiros a month ago ec1d428
mover proyecto de biblioteca a subfolder
7 files changed, 57 insertions(+), 8 deletions(-)

R build.xml => Lib/build.xml
R nbproject/{build-impl.xml => ect/build-impl.xml}
R nbproject/{genfiles.properties => ect/genfiles.properties}
R nbproject/{project.properties => ect/project.properties}
R nbproject/{project.xml => ect/project.xml}
R src/com/eduardoquiros/mainbrain/ui/{Panel.form => /ui/Panel.form}
R src/com/eduardoquiros/mainbrain/ui/{Panel.java => /ui/Panel.java}
R build.xml => Lib/build.xml +0 -0

R nbproject/build-impl.xml => Lib/nbproject/build-impl.xml +0 -0

R nbproject/genfiles.properties => Lib/nbproject/genfiles.properties +0 -0

R nbproject/project.properties => Lib/nbproject/project.properties +0 -0

R nbproject/project.xml => Lib/nbproject/project.xml +0 -0

R src/com/eduardoquiros/mainbrain/ui/Panel.form => Lib/src/com/eduardoquiros/mainbrain/ui/Panel.form +2 -3
@@ 44,16 44,15 @@
                  <Group type="102" attributes="0">
                      <Component id="finLabel" min="-2" max="-2" attributes="0"/>
                      <EmptySpace type="separate" max="-2" attributes="0"/>
                      <Component id="codeLabel" min="-2" pref="98" max="-2" attributes="0"/>
                      <EmptySpace max="32767" attributes="0"/>
                      <Component id="codeLabel" max="32767" attributes="0"/>
                  </Group>
                  <Group type="102" alignment="0" attributes="0">
                      <Component id="parcialesLabel" min="-2" max="-2" attributes="0"/>
                      <EmptySpace pref="149" max="32767" attributes="0"/>
                      <Component id="intentoField" min="-2" pref="109" max="-2" attributes="0"/>
                      <EmptySpace min="-2" pref="72" max="-2" attributes="0"/>
                  </Group>
              </Group>
              <EmptySpace min="-2" pref="72" max="-2" attributes="0"/>
          </Group>
          <Group type="102" alignment="1" attributes="0">
              <EmptySpace min="0" pref="0" max="32767" attributes="0"/>

R src/com/eduardoquiros/mainbrain/ui/Panel.java => Lib/src/com/eduardoquiros/mainbrain/ui/Panel.java +55 -5
@@ 5,17 5,34 @@
 */
package com.eduardoquiros.mainbrain.ui;

import java.util.Random;

/**
 *
 * @author eduardo
 */
public class Panel extends javax.swing.JPanel {

    int intentosRestantes = 8;
    private final String[] colours;
    private String code = "";
    boolean correct = false;

    /**
     * Creates new form Panel
     */
    public Panel() {
        initComponents();
        this.codeLabel.setVisible(false);
        this.finLabel.setVisible(false);
        this.colours = new String[]{"A", "R", "B", "N", "V", "M"};
        int i = 0;
        while (i < 4) {
            int rnd = new Random().nextInt(colours.length - 1);
            code += colours[rnd];
            i++;
        }

    }

    /**


@@ 87,13 104,12 @@ public class Panel extends javax.swing.JPanel {
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(finLabel)
                        .addGap(18, 18, 18)
                        .addComponent(codeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addComponent(codeLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(parcialesLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 149, Short.MAX_VALUE)
                        .addComponent(intentoField, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(72, 72, 72))))
                        .addComponent(intentoField, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(72, 72, 72))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(intentarButton)


@@ 127,13 143,47 @@ public class Panel extends javax.swing.JPanel {
    }// </editor-fold>//GEN-END:initComponents

    private void intentarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_intentarButtonActionPerformed
        // TODO add your handling code here:
        int[] aciertos = checkCode(this.intentoField.getText().substring(0, 4));
        if (aciertos[0] == 4) {
            intentosRestantes = 0;
            correct = true;
        }
        if (intentosRestantes > 0) {
            intentosRestantes--;
        }
        if (intentosRestantes == 0) {
            this.intentarButton.setEnabled(false);
            this.codeLabel.setText(code);
            this.codeLabel.setVisible(true);
            this.finLabel.setVisible(true);
            if (correct)
                this.title.setText("¬°Felicidades!");
            else
                this.title.setText("Derrota...");
        }
        this.parcialesLabel.setText("Aciertos Parciales: " + aciertos[1]);
        this.totalesLabel.setText("Aciertos Totales: " + aciertos[0]);
        this.intentosLabel.setText("Intentos Restantes: " + intentosRestantes);

    }//GEN-LAST:event_intentarButtonActionPerformed

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

    public int[] checkCode(String test) {
        int[] aciertos = new int[]{0, 0};
        int posicion = 0;
        for (var letter : test.toCharArray()) {
            if (letter == code.charAt(posicion)) {
                aciertos[0]++;
            } else if (code.contains(test.substring(posicion))) {
                aciertos[1]++;
            }
        }
        return aciertos;
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel codeLabel;