Пример #1
0
 /** This method will create a frame to show the user all the scores in order. */
 protected void createHighscoreFrame() {
   highScoreFrame = new Highscore();
   highScoreFrame.setVisible(true);
   highScoreFrame.setBounds(
       250, // left
       10, // top
       10, // bottom
       10); // right
   highScoreFrame.newGame.addActionListener(new NewGameButtonListener());
   highScoreFrame.pack();
   desktop.add(highScoreFrame);
 }
Пример #2
0
  public void paint(Graphics g) {
    super.paint(g);
    if (screen.equalsIgnoreCase("title")) {
      MyPanel.score = 0;
      hs = new Highscore();
      c.removeAll();
      c.add(ts);
      panel = null;
      ts.revalidate();
    } else if (screen.equalsIgnoreCase("instructions")) {
      c.removeAll();
      c.add(instructions);
      instructions.revalidate();
    } else if (screen.equalsIgnoreCase("mode")) {
      c.removeAll();
      c.add(mode);
      mode.revalidate();
    } else if (screen.equalsIgnoreCase("difficulty")) {
      c.removeAll();
      c.add(dif);
      dif.revalidate();
    } else if (screen.equalsIgnoreCase("highscore")) {
      if (hs.returnCount() == 0) {
        c.removeAll();
        c.add(hs);
        c.validate();
      }
    } else if (screen.equalsIgnoreCase("gameover")) {
      if (!once) {
        c.removeAll();
        c.add(gg);
        once = true;
        c.validate();
      }

    } else {
      if (once) {
        c.removeAll();
        panel = new MyPanel(THA.WIDTH, THA.HEIGHT, ai, diff);
        c.setLayout(new BorderLayout());
        c.add(panel.returnNs(), BorderLayout.WEST);
        c.add(panel, BorderLayout.CENTER);
        c.add(btns, BorderLayout.SOUTH);
        c.add(panel.returnAmmo(), BorderLayout.EAST);
        c.validate();
        once = false;
      }
    }
    repaint();
  }
Пример #3
0
  public void actionPerformed(ActionEvent e) {
    String command = e.getActionCommand();
    if (command.equalsIgnoreCase("Exit")) { // Exits the game
      System.exit(0);
      // MyFrame.screen = "title";
      // MyFrame.once=true;

    } else if (command.equalsIgnoreCase("Submit")) {
      String user = name.getText(); // name of user
      if (user.equalsIgnoreCase("") || user == null) {
        user = "******";
      }
      try {
        Highscore.write(MyPanel.score, user);
      } catch (IOException e1) {
        e1.printStackTrace();
      }
      System.exit(0);
      // MyFrame.screen = "title";
      // MyFrame.once=true;

    }
  }
Пример #4
0
  // Method that shows the top 5 scores in the ScoreScreen panel
  public void ShowHighscore(ScreenFrame frame, ServerConnection server, Parsers parser) {

    //
    try {

      // Initiates highscore class
      Highscore highscores = new Highscore();

      // Instantiates highscore object..?
      highscores = parser.scoreParser(server.get("scores/"), highscores);

      // Sets the labels in ScoreScreen panel equal to the obtained scores from servers
      frame
          .getHighscore()
          .getLblFirst()
          .setText("#1: " + String.valueOf(highscores.getFirstPlace() + " points"));
      frame
          .getHighscore()
          .getLblSecond()
          .setText("#2: " + String.valueOf(highscores.getSecondPlace() + " points"));
      frame
          .getHighscore()
          .getLblThird()
          .setText("#3: " + String.valueOf(highscores.getThirdPlace() + " points"));
      frame
          .getHighscore()
          .getLblFourth()
          .setText("#4: " + String.valueOf(highscores.getFourthPlace() + " points"));
      frame
          .getHighscore()
          .getLblFifth()
          .setText("#5: " + String.valueOf(highscores.getFifthPlace() + " points"));

      //
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Пример #5
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