示例#1
0
  public static IUmenu mainAE() {
    PerfilesBD coleccion = new PerfilesBD();
    final PerfilesBD perfilesDB = coleccion;
    String ip = "";
    try {
      ip = InetAddress.getLocalHost().getHostAddress();
    } catch (Exception exp) {
    }
    ipServer = ip;
    final String ipDef = ip;
    if (!coleccion.estaMontadoServidor()) {

      new Thread() {
        public void run() {

          try {
            Servidor servidor = new Servidor();
            servidor.ejecutarServidor();
          } catch (Exception e) {
            System.out.println(e);
          }
        }
      }.start();
      /*new Thread()
      {
              public void run()
              {

                      try
                      {
                              ServidorChat servidorChat = new ServidorChat();
                              servidorChat.ejecutarServidor();
                      }
                      catch (Exception e)
                      {
                              System.out.println(e);
                      }
              }
      }.start();*/
      new Thread() {
        public void run() {

          try {
            ClienteAdm clienteAdm = new ClienteAdm(ipDef);
          } catch (Exception e) {
            System.out.println(e);
          }
        }
      }.start();
    }

    String hostOut = coleccion.getHostServidor();

    IUmenu a = new IUmenu(hostOut);
    a.setBounds(120, 70, 800, 600);
    a.setUndecorated(true);
    a.getRootPane().setWindowDecorationStyle(0);
    a.setDefaultCloseOperation(a.DO_NOTHING_ON_CLOSE);
    a.setResizable(false);
    a.setVisible(true);
    menu = a;
    return a;
  }
示例#2
0
  // manejo de eventos de turno y los mapas
  public void actionPerformed(ActionEvent e) {
    if (estad == e.getSource()) {
      efectos.reproducirEfectoSonido("Klick");
      // IUpanel02.mainAE();   -----------------------------------------------
      /// setVisible(false);
    }
    if (registrar == e.getSource()) {
      efectos.reproducirEfectoSonido("Klick");
      OpcionesPerfiles.perfiles.mainAE();
      setVisible(false);
    }
    if (facil == e.getSource()) {
      efectos.reproducirEfectoSonido("Klick");
      String nomb = "";
      PerfilesBD coleccion = new PerfilesBD();
      int numPer = 0;
      numPer = coleccion.numeroDePerfiles();
      Perfil perfilesMostrar[] = null;

      if (numPer == 0) {
        perfilesMostrar = new Perfil[4];

        for (int idx = 0; idx < 4; idx++) {
          perfilesMostrar[idx] =
              new Perfil("Asesinator" + (idx + 1), "predt" + (idx + 1) + ".jpg", "123" + idx);
          coleccion.agregarPerfil(perfilesMostrar[idx]);
        }
      }

      try {
        do {
          nomb =
              JOptionPane.showInputDialog(null, "Ingrese Nombre de Jugador Humano", "Asesinator1");

        } while (nomb.length() == 0);

        if (nomb.equals("Asesinator1")
            || nomb.equals("Asesinator2")
            || nomb.equals("Asesinator3")
            || nomb.equals("Asesinator4")) {
          MenuCrearJuego.menu.mainAE(1, nomb, "PC");
          setVisible(false);
          return;
        }

        JLabel jPassword = new JLabel("porfavor ingrese la contraseña ");
        JTextField password = new JPasswordField();
        Object[] ob = {jPassword, password};

        int result =
            JOptionPane.showConfirmDialog(null, ob, "Contraseña", JOptionPane.OK_CANCEL_OPTION);

        String contraseNa = "";
        if (result == JOptionPane.OK_OPTION) {
          contraseNa = password.getText();
        }
        if (result == JOptionPane.CANCEL_OPTION) {
          return;
        }

        if (coleccion.estaRegistrado(contraseNa)) {
          MenuCrearJuego.menu.mainAE(1, nomb, "PC");
          setVisible(false);
        } else {
          JOptionPane.showMessageDialog(
              this,
              "No esta Registrado, usted debe registrarse previamente!",
              "ERROR",
              JOptionPane.ERROR_MESSAGE);
        }
      } catch (Exception exp) {
      }
      return;
    }
    if (dific == e.getSource()) {
      efectos.reproducirEfectoSonido("Klick");
      String nomb = "";
      PerfilesBD coleccion = new PerfilesBD();
      int numPer = 0;
      numPer = coleccion.numeroDePerfiles();
      Perfil perfilesMostrar[] = null;

      if (numPer == 0) {
        perfilesMostrar = new Perfil[4];

        for (int idx = 0; idx < 4; idx++) {
          perfilesMostrar[idx] =
              new Perfil("Asesinator" + (idx + 1), "predt" + (idx + 1) + ".jpg", "123" + idx);
          coleccion.agregarPerfil(perfilesMostrar[idx]);
        }
      }

      try {
        do {
          nomb =
              JOptionPane.showInputDialog(null, "Ingrese Nombre de Jugador Humano", "Asesinator1");

        } while (nomb.length() == 0);

        if (nomb.equals("Asesinator1")
            || nomb.equals("Asesinator2")
            || nomb.equals("Asesinator3")
            || nomb.equals("Asesinator4")) {
          MenuCrearJuego.menu.mainAE(2, nomb, "PC");
          setVisible(false);
          return;
        }

        JLabel jPassword = new JLabel("porfavor ingrese la contraseña ");
        JTextField password = new JPasswordField();
        Object[] ob = {jPassword, password};

        int result =
            JOptionPane.showConfirmDialog(null, ob, "Contraseña", JOptionPane.OK_CANCEL_OPTION);

        String contraseNa = "";
        if (result == JOptionPane.OK_OPTION) {
          contraseNa = password.getText();
        }
        if (result == JOptionPane.CANCEL_OPTION) {
          return;
        }

        if (coleccion.estaRegistrado(contraseNa)) {
          MenuCrearJuego.menu.mainAE(2, nomb, "PC");
          setVisible(false);
        } else {
          JOptionPane.showMessageDialog(
              this,
              "No esta Registrado, usted debe registrarse previamente!",
              "ERROR",
              JOptionPane.ERROR_MESSAGE);
        }
      } catch (Exception exp) {
      }
      return;
    }

    if (red == e.getSource()) {
      efectos.reproducirEfectoSonido("Klick");
      String nomb = "";
      PerfilesBD coleccion = new PerfilesBD();
      final PerfilesBD perfilesDB = coleccion;
      int numPer = 0;
      numPer = coleccion.numeroDePerfiles();
      Perfil perfilesMostrar[] = null;

      if (numPer == 0) {
        perfilesMostrar = new Perfil[4];

        for (int idx = 0; idx < 4; idx++) {
          perfilesMostrar[idx] =
              new Perfil("Asesinator" + (idx + 1), "predt" + (idx + 1) + ".jpg", "123" + idx);
          coleccion.agregarPerfil(perfilesMostrar[idx]);
        }
      }

      try {
        do {
          nomb =
              JOptionPane.showInputDialog(null, "Ingrese Nombre de Jugador Humano", "Asesinator1");

        } while (nomb.length() == 0);
        final String nomb2 = nomb;
        Perfil perfil = null;
        if (nomb.equals("Asesinator1")
            || nomb.equals("Asesinator2")
            || nomb.equals("Asesinator3")
            || nomb.equals("Asesinator4")) {
          if (nomb.equals("Asesinator1")) {
            if (coleccion.estaConectado("1230")) {
              JOptionPane.showMessageDialog(
                  this, "El perfil ya se encuentra en uso!", "ERROR", JOptionPane.ERROR_MESSAGE);
              return;
            }
          }
          if (nomb.equals("Asesinator2")) {
            if (coleccion.estaConectado("1231")) {
              JOptionPane.showMessageDialog(
                  this, "El perfil ya se encuentra en uso!", "ERROR", JOptionPane.ERROR_MESSAGE);
              return;
            }
          }
          if (nomb.equals("Asesinator3")) {
            if (coleccion.estaConectado("1232")) {
              JOptionPane.showMessageDialog(
                  this, "El perfil ya se encuentra en uso!", "ERROR", JOptionPane.ERROR_MESSAGE);
              return;
            }
          }
          if (nomb.equals("Asesinator4")) {
            if (coleccion.estaConectado("1233")) {
              JOptionPane.showMessageDialog(
                  this, "El perfil ya se encuentra en uso!", "ERROR", JOptionPane.ERROR_MESSAGE);
              return;
            }
          }

          if (nomb.equals("Asesinator1")) {
            coleccion.agregarConectado("1230");
          }
          if (nomb.equals("Asesinator2")) {
            coleccion.agregarConectado("1231");
          }
          if (nomb.equals("Asesinator3")) {
            coleccion.agregarConectado("1232");
          }
          if (nomb.equals("Asesinator4")) {
            coleccion.agregarConectado("1233");
          }

          if (!coleccion.estaMontadoServidor()) {

            int numJugadores = 2;
            boolean siga = false;
            do {
              try {
                numJugadores =
                    Integer.parseInt(
                        JOptionPane.showInputDialog(
                            this,
                            "señor jugador, por ser el primero en elegir juego en red,\n"
                                + " ha sido elegido como administrador de la partida,\n"
                                + " `por favor ingrese el numero de jugadores [2,50]"));
              } catch (Exception exp) {
                continue;
              }
              if ((numJugadores >= 2) && (numJugadores < 50)) {
                siga = true;
              }

            } while (!siga);

            cliente.enviarAdmi(numJugadores);
            coleccion.conectar_desconectarServidor(true, ipServer);
            JOptionPane.showMessageDialog(
                this,
                "se modifica el numero de jugadores de la clase Administrador : " + numJugadores);
          }
          MenuCrearJuego.menu.mainAE(1, nomb, "Red");
          MenuCrearJuego.menu.setCliente(cliente);
          setVisible(false);

          return;
        }

        JLabel jPassword = new JLabel("porfavor ingrese la contraseña ");
        JTextField password = new JPasswordField();
        Object[] ob = {jPassword, password};

        int result =
            JOptionPane.showConfirmDialog(null, ob, "Contraseña", JOptionPane.OK_CANCEL_OPTION);

        String contraseNa = "";
        if (result == JOptionPane.OK_OPTION) {
          contraseNa = password.getText();
        }
        if (result == JOptionPane.CANCEL_OPTION) {
          return;
        }

        if (coleccion.estaRegistrado(contraseNa)) {
          if (coleccion.estaConectado(contraseNa)) {
            JOptionPane.showMessageDialog(
                this, "El perfil ya se encuentra en uso!", "ERROR", JOptionPane.ERROR_MESSAGE);
            return;
          }

          coleccion.agregarConectado(contraseNa);

          if (!coleccion.estaMontadoServidor()) {

            int numJugadores = 2;
            boolean siga = false;
            do {
              try {
                numJugadores =
                    Integer.parseInt(
                        JOptionPane.showInputDialog(
                            this,
                            "señor jugador, por ser el primero en elegir juego en red,\n"
                                + " ha sido elegido como administrador de la partida,\n"
                                + " `por favor ingrese el numero de jugadores [2,50]"));
              } catch (Exception exp) {
                JOptionPane.showMessageDialog(
                    this, "Error de datos ", "Error", JOptionPane.ERROR_MESSAGE);
                continue;
              }
              if ((numJugadores >= 2) && (numJugadores < 50)) {
                siga = true;
              } else
                JOptionPane.showMessageDialog(
                    this, "Error de datos ", "Error", JOptionPane.ERROR_MESSAGE);

            } while (!siga);
            cliente.enviarAdmi(numJugadores);
            coleccion.conectar_desconectarServidor(true, ipServer);
          }
          MenuCrearJuego.menu.mainAE(1, nomb, "Red");
          MenuCrearJuego.menu.setCliente(cliente);
          setVisible(false);
        } else {
          JOptionPane.showMessageDialog(
              this,
              "No esta Registrado, usted debe registrarse previamente!",
              "ERROR",
              JOptionPane.ERROR_MESSAGE);
        }
      } catch (Exception exp) {
      }
      return;
    }

    if (salir == e.getSource()) {
      efectos.reproducirEfectoSonido("Klick");
      PerfilesBD coleccion = new PerfilesBD();
      // pregunta si de verdad se desea salir del juego
      int n =
          JOptionPane.showConfirmDialog(
              null,
              "Seguro que deseas SALIR?",
              "END GAME",
              JOptionPane.YES_NO_OPTION,
              JOptionPane.QUESTION_MESSAGE);

      if (n == JOptionPane.YES_OPTION) {
        System.exit(12);
      }
    }
  }