Example #1
0
  public static void init(GameController gc, Registry r) {
    int version;

    registry = r;

    resolutions = new ArrayList();
    resolutions.add("800x600");
    resolutions.add("1024x768");
    resolutions.add("1152x864");
    resolutions.add("1280x720");
    resolutions.add("1280x768");
    resolutions.add("1280x800");
    resolutions.add("1280x960");
    resolutions.add("1280x1024");
    resolutions.add("1360x768");
    resolutions.add("1366x768");
    resolutions.add("1440x900");
    resolutions.add("1600x900");
    resolutions.add("1600x1024");
    resolutions.add("1680x1050");
    resolutions.add("1920x1080");
    resolutions.add("1920x1200");
    // resolutions.add("Full Screen");

    players = new ArrayList<Player>();
    blockManagers = new ArrayList<BlockManager>();
    placeableManagers = new ArrayList<PlaceableManager>();
    monsterManagers = new ArrayList<MonsterManager>();

    // try to load the settings file
    try {
      FileInputStream settingsFile = new FileInputStream("Settings.dat");
      ObjectInputStream settings = new ObjectInputStream(settingsFile);

      version = ((Integer) settings.readObject()).intValue();
      resolution = ((Integer) settings.readObject()).intValue();
      volumeMusic = ((Integer) settings.readObject()).intValue();
      volumeFX = ((Integer) settings.readObject()).intValue();
      buttonMoveRight = ((Integer) settings.readObject()).intValue();
      buttonMoveLeft = ((Integer) settings.readObject()).intValue();
      buttonJump = ((Integer) settings.readObject()).intValue();
      buttonAction = ((Integer) settings.readObject()).intValue();
      buttonRobot = ((Integer) settings.readObject()).intValue();
      buttonInventory = ((Integer) settings.readObject()).intValue();
      buttonPause = ((Integer) settings.readObject()).intValue();

      settings.close();
    } catch (Exception e) {
      EIError.debugMsg(e.getMessage(), EIError.ErrorLevel.Warning);
    }

    if (volumeMusic < -1 || volumeMusic > 10) {
      volumeMusic = 8;
    }
    if (volumeMusic == 0) {
      volumeMusic = 8;
    }
    if (volumeMusic == -1) {
      volumeMusic = 0;
    }

    if (volumeFX < -1 || volumeFX > 10) {
      volumeFX = 8;
    }
    if (volumeFX == 0) {
      volumeFX = 8;
    }
    if (volumeFX == -1) {
      volumeFX = 0;
    }

    if (buttonMoveRight == 0) {
      buttonMoveRight = KeyEvent.VK_D;
    }
    if (buttonMoveLeft == 0) {
      buttonMoveLeft = KeyEvent.VK_A;
    }
    if (buttonJump == 0) {
      buttonJump = KeyEvent.VK_SPACE;
    }
    if (buttonAction == 0) {
      buttonAction = KeyEvent.VK_E;
    }
    if (buttonRobot == 0) {
      buttonRobot = KeyEvent.VK_R;
    }
    if (buttonInventory == 0) {
      buttonInventory = KeyEvent.VK_I;
    }
    if (buttonPause == 0) {
      buttonPause = KeyEvent.VK_P;
    }

    // try to load the players
    for (int i = 1; i <= NUMBER_OF_PLAYER_SLOTS; i++) {
      try {
        FileInputStream playerFile = new FileInputStream("Player" + i + ".dat");
        ObjectInputStream playerInfo = new ObjectInputStream(playerFile);

        version = ((Integer) playerInfo.readObject()).intValue();
        players.add((Player) playerInfo.readObject());
        blockManagers.add((BlockManager) playerInfo.readObject());
        placeableManagers.add((PlaceableManager) playerInfo.readObject());

        MonsterManager mm = null;
        if (version >= 2) {
          mm = (MonsterManager) playerInfo.readObject();
        }
        if (mm == null) {
          mm = new MonsterManager(gc, r);
        }
        monsterManagers.add(mm);

        playerInfo.close();
        EIError.debugMsg("Added Player " + i);
      } catch (Exception e) {
        if (players.size() >= i) {
          players.set(i - 1, null);
        } else {
          players.add(null);
        }
        if (blockManagers.size() >= i) {
          blockManagers.set(i - 1, null);
        } else {
          blockManagers.add(null);
        }
        if (placeableManagers.size() >= i) {
          placeableManagers.set(i - 1, null);
        } else {
          placeableManagers.add(null);
        }
        if (monsterManagers.size() >= i) {
          monsterManagers.set(i - 1, null);
        } else {
          monsterManagers.add(null);
        }
        EIError.debugMsg(
            "Couldn't load Player " + i + " " + e.getMessage(), EIError.ErrorLevel.Error);
      }
    }
  }
 private void readObject(ObjectInputStream aInputStream) throws Exception {
   aInputStream.defaultReadObject();
 }