Exemple #1
0
  public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_ESCAPE && gamerunner.running) {

      Graphics gr = this.getGraphics();
      gr.setFont(new Font("TimesRoman", Font.PLAIN, 40));
      gr.drawString("PAUSE", (int) this.getWidth() / 2, this.getHeight() / 2);
      if (!online) {
        gamerunner.running = false;
      }
      if (soundan) {} // end of if
      Menu menu = new Menu(this);
      // volume.setValue(vol);
    } else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
      gamerunner.running = true;
      if (soundan) {} // end of if
    } // end of if-else
    else if (e.getKeyCode() == KeyEvent.VK_R && !online) {
      restartGame();
    } else if (e.getKeyCode() == KeyEvent.VK_F11) {
      dispose();
      setUndecorated(true);
      String[] arguments = {"fullscreen"};
      new JavaGame(arguments);
    } else if (e.getKeyCode() == KeyEvent.VK_ENTER && online) {
      String message =
          JOptionPane.showInputDialog(null, "Chat", "Nachricht", JOptionPane.PLAIN_MESSAGE);
      try {
        if (!message.isEmpty()) {
          client.sendNewChatMessage(player[client.id].name, message);
        }
      } catch (IOException e1) {
        e1.printStackTrace();
      }
    }
  }
Exemple #2
0
 // If this is a new installation, ask the user for a
 // port for the server; otherwise, return the negative
 // of the configured port. If the user selects an illegal
 // port, return zero.
 private int getPort() {
   // Note: directory points to the parent of the CTP directory.
   File ctp = new File(directory, "CTP");
   if (suppressFirstPathElement) ctp = ctp.getParentFile();
   File config = new File(ctp, "config.xml");
   if (!config.exists()) {
     // No config file - must be a new installation.
     // Figure out whether this is Windows or something else.
     String os = System.getProperty("os.name").toLowerCase();
     int defPort = ((os.contains("windows") && !programName.equals("ISN")) ? 80 : 1080);
     int userPort = 0;
     while (userPort == 0) {
       String port =
           JOptionPane.showInputDialog(
               null,
               "This is a new "
                   + programName
                   + " installation.\n\n"
                   + "Select a port number for the web server.\n\n",
               Integer.toString(defPort));
       try {
         userPort = Integer.parseInt(port.trim());
       } catch (Exception ex) {
         userPort = -1;
       }
       if ((userPort < 80) || (userPort > 32767)) userPort = 0;
     }
     return userPort;
   } else {
     try {
       Document doc = getDocument(config);
       Element root = doc.getDocumentElement();
       Element server = getFirstNamedChild(root, "Server");
       String port = server.getAttribute("port");
       return -Integer.parseInt(port);
     } catch (Exception ex) {
     }
   }
   return 0;
 }
Exemple #3
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);
      }
    }
  }
Exemple #4
0
  public JavaGame(String[] args) {
    this.args = args;
    updater = new Updater(this);
    highscore = new Highscore(this);
    eventHandler = new EventHandler(this);
    eventHandler.registerTestEvents();

    setTitle("Survive-JavaGame"); // Fenstertitel setzen
    setSize(1200, 900); // Fenstergröße einstellen
    addWindowListener(new WindowListener());
    setLocationRelativeTo(null);

    try {
      arg = args[0];
    } catch (ArrayIndexOutOfBoundsException e) {
      arg = "nothing";
    }
    if (arg.equals("fullscreen")) {
      setUndecorated(true); // "Vollbild"
      setSize(
          (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth() - 200,
          (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth());
      setLocation(0, 0);
    }
    setVisible(true);
    setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));

    try {
      /*URI Path = URLDecoder.decode(getClass().getClassLoader().getResource("texture").toURI();//, "UTF-8"); //Pfad zu den Resourcen
      File F = new File(Path);
      basePath = F;
      System.out.println(basePath);
      */
      File File = new File((System.getenv("APPDATA")));
      basePath = new File(File, "/texture");
      backgroundTexture = new File(basePath, "/hintergrund.jpg");
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    try {
      backgroundImage = ImageIO.read(backgroundTexture);
    } catch (IOException exeption) {

    }

    if (soundan) {
      currentVolume = 80;
    } // end of if

    dbImage = createImage(1920, 1080);
    // dbGraphics = dbImage.getGraphics();

    // Texturen Liste

    // Ebenen Liste

    ebenen[0][0] = 91;
    ebenen[0][1] = 991; // Main Ebene: Kann nicht durchschrittenwerden indem down gedrückt wird
    ebenen[0][2] = 563;

    ebenen[1][0] = 387; // x1
    ebenen[1][1] = 524; // x2
    ebenen[1][2] = 454; // y

    ebenen[2][0] = 525;
    ebenen[2][1] = 645;
    ebenen[2][2] = 350;

    ebenen[3][0] = 246;
    ebenen[3][1] = 365;
    ebenen[3][2] = 351;

    ebenen[4][0] = 760;
    ebenen[4][1] = 870;
    ebenen[4][2] = 294;

    ebenen[5][0] = 835;
    ebenen[5][1] = 969;
    ebenen[5][2] = 441;

    // Spieler

    // I'm in Space! SPACE!
    player[1] =
        new Player(
            (int) (Math.random() * (ebenen[0][1] - ebenen[0][0]) + ebenen[0][0]),
            0,
            false,
            67,
            100,
            texture[0],
            shottexture[0],
            KeyEvent.VK_A,
            KeyEvent.VK_D,
            KeyEvent.VK_W,
            KeyEvent.VK_S,
            KeyEvent.VK_Q,
            1,
            35,
            highscore.getName(1));
    player[2] =
        new Bot(
            (int) (Math.random() * (ebenen[0][1] - ebenen[0][0]) + ebenen[0][0]),
            0,
            false,
            67,
            100,
            texture[1],
            shottexture[1],
            KeyEvent.VK_J,
            KeyEvent.VK_L,
            KeyEvent.VK_I,
            KeyEvent.VK_K,
            KeyEvent.VK_U,
            2,
            35,
            highscore.getName(1));
    player[3] =
        new Bot(
            (int) (Math.random() * (ebenen[0][1] - ebenen[0][0]) + ebenen[0][0]),
            0,
            false,
            67,
            100,
            texture[2],
            shottexture[2],
            KeyEvent.VK_LEFT,
            KeyEvent.VK_RIGHT,
            KeyEvent.VK_UP,
            KeyEvent.VK_DOWN,
            KeyEvent.VK_ENTER,
            3,
            35,
            highscore.getName(1));

    player[1].laden(this);
    player[2].laden(this);
    player[3].laden(this);

    this.addKeyListener(player[1]);
    this.addKeyListener(player[2]);
    this.addKeyListener(player[3]);

    this.addKeyListener(this);

    int result;
    Object[] options = {"SinglePlayer", "MultiPlayer"};
    if (arg.equals("dedicated")) {
      Server server = new Server();
      this.server = true;
      setVisible(false);

    } else {
      if ((result =
              JOptionPane.showOptionDialog(
                  null,
                  "Treffen Sie eine Auswahl",
                  "Alternativen",
                  JOptionPane.DEFAULT_OPTION,
                  JOptionPane.INFORMATION_MESSAGE,
                  null,
                  options,
                  options[0]))
          == 1) {
        client = new Client(this);
        online = true;
        while ((onlinename =
                    JOptionPane.showInputDialog(
                        null,
                        "Geben Sie Ihren Namen ein",
                        "Eine Eingabeaufforderung",
                        JOptionPane.PLAIN_MESSAGE))
                .isEmpty()
            && onlinename != null) {}

        Object[] optionsmp = {"Host", "Client"};
        if ((result =
                JOptionPane.showOptionDialog(
                    null,
                    "Treffen Sie eine Auswahl",
                    "Alternativen",
                    JOptionPane.DEFAULT_OPTION,
                    JOptionPane.INFORMATION_MESSAGE,
                    null,
                    optionsmp,
                    optionsmp[0]))
            == 0) {
          Server server = new Server();
          this.server = true;
        } else if (online) {
          while ((serveradresse =
                      JOptionPane.showInputDialog(
                          null,
                          "Geben Sie die Serveradresse ein",
                          "Eine Eingabeaufforderung",
                          JOptionPane.PLAIN_MESSAGE))
                  .isEmpty()
              && serveradresse != null) {}
        }
      }
    }
    if (!arg.equals("dedicated")) {
      gamerunner = new GameRunner(player, this);
      DamageLogig = new damageLogig(gamerunner);
    }

    if (online) {
      try {
        client.initialise(serveradresse, 9876);
        client.start();
      } catch (SocketException e) {
        e.printStackTrace();
      } catch (UnknownHostException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  } // end of init