Ejemplo n.º 1
0
  public GameApplication(
      Game game,
      boolean multiplayer,
      String joinAdress,
      String playerId,
      int playerNumber,
      String map) {
    this.game = game;
    this.map = map;

    setPauseOnLostFocus(false);
    setShowSettings(false);

    if (joinAdress.isEmpty()) {
      server = new GameServer();
      if (server.isStarted() == false) {
        System.out.println("Error cannot start server");
        System.exit(0);
      }

      joinAdress = "localhost";
    }

    if (multiplayer) {
      try {
        client = new GameClient(game, joinAdress, playerId, playerNumber);
      } catch (Exception e) {
        if (server != null) {
          server.close();
          System.out.println("Client error " + e.getMessage());
          System.exit(0);
        }
      }
    }

    try {
      FileInputStream fis = new FileInputStream(new File("settings.txt"));
      AppSettings settings = new AppSettings(true);
      settings.load(new BufferedInputStream(fis));
      setSettings(settings);
    } catch (Exception e) {
      AppSettings settings = new AppSettings(true);
      settings.setResolution(1024, 768);
      settings.setFrameRate(50);
      settings.setFullscreen(false);
      settings.setTitle("JPenguin");

      setSettings(settings);
    }
  }
Ejemplo n.º 2
0
  @Override
  public void destroy() {
    super.destroy();

    if (client != null) {
      client.close();
    }

    if (server != null) {
      server.close();
    }

    game.getFogOfWar().destroy();
  }