Exemple #1
0
 public void loadLevel() {
   if (Arguments.getPath() == null)
     fileChooser.setCurrentDirectory(new File(System.getProperty("user.home")));
   else {
     fileChooser.setCurrentDirectory(new File(Arguments.getPath()));
   }
   int result = JFileChooser.CANCEL_OPTION;
   if (Arguments.getSaveFile() == null) tryedArg = true;
   if (tryedArg == true) result = fileChooser.showOpenDialog(DisplayWindow.getFrame());
   if (result == JFileChooser.APPROVE_OPTION || Arguments.getSaveFile() != null) {
     File path = fileChooser.getSelectedFile();
     if (tryedArg == false && Arguments.getSaveFile() != null) {
       path = new File(Arguments.getPath() + "/" + Arguments.getSaveFile());
       tryedArg = true;
     }
     File levelFile = new File(path.getAbsolutePath() + "/world.json");
     if (levelFile != null) {
       if (levelFile.exists()) {
         levelName = path.getName();
         Log.info("Loading level [" + levelName + "]...");
         try {
           levelImage = Loader.loadBufferedImage(levelFile.toString().replace(".json", ".png"));
           CordPane.levelWidth = width = levelImage.getWidth() / 32;
           CordPane.levelHeight = height = levelImage.getHeight() / 32;
           loadEntityData(path);
         } catch (ParseException | IOException e) {
           Log.warn("Loading level [" + levelName + "]... FAILED");
           Log.stackTrace(e);
           return;
         }
         Log.info("Loading level [" + levelName + "]... SUCCESS");
         loaded = true;
       } else {
         Log.warn("This is not a valid save level");
         Dialogs.error("This is not a valid save level", Strings._title);
         loadLevel();
       }
     }
   }
   if (!loaded) System.exit(0);
 }
Exemple #2
0
 public void init(GameContainer container, GameThread game) {
   DisplayWindow.setUpGameContainer(container);
   game.addState(new IntroState(game, width, height, State.INTRO.ordinal()));
   game.addState(new MenuState(game, width, height, State.MENU.ordinal()));
   game.addState(new GameState(game, width, height, State.GAME.ordinal()));
 }