示例#1
0
  public static void updateSave(String saveLocation, Player p, GameBoard currentMap)
      throws IOException {
    File playerFile = new File(saveLocation + "/player.txt");
    BufferedWriter w = new BufferedWriter(new FileWriter(playerFile));

    Save.savePlayerProfession(w, p.getProfession());
    Save.savePlayerStatus(w, p);
    w.close();

    BufferedWriter r = new BufferedWriter(new FileWriter(saveLocation + "/" + currentMap.mapID));
    Save.saveBoard(currentMap, r);
    Save.saveEntities(currentMap, r);
    r.close();

    File director = new File(saveLocation + "/saveInformation.txt");
    BufferedReader a = new BufferedReader(new FileReader(director));
    String name = a.readLine();
    a.close();

    BufferedWriter b = new BufferedWriter(new FileWriter(director));
    b.write(name);
    b.newLine();
    b.write(currentMap.mapID);
    b.close();
  }
示例#2
0
  /**
   * Make a new save from scratch. generates a whole dungeon, level by level, and saves it to the
   * disk
   *
   * @param fileLocation the file location for the save
   * @param nameofSave the name of the save
   * @param p the profession generated by the class generator
   * @return the save generated
   * @throws IOException Signals that an I/O exception has occurred.
   * @throws SlickException the slick exception
   */
  public static Save makeNewSave(String fileLocation, String nameofSave, Profession p)
      throws SlickException {
    try {
      new File(fileLocation).mkdir();
      File director = new File(fileLocation + "/saveInformation.txt");
      BufferedWriter r = new BufferedWriter(new FileWriter(director));
      r.write(nameofSave);
      r.newLine();
      r.write("floor0.map");
      r.close();

      DungeonMap map = new DungeonMap(16);

      Tile spawnTile = null;

      for (int i = 0; i < map.getDepth(); i++) {
        File floorFile = new File(fileLocation + map.getFloorName(i));
        floorFile.createNewFile();
        r = new BufferedWriter(new FileWriter(floorFile));

        GameBoard gameBoard = map.makeBoard(i);

        if (i == 0) {
          spawnTile = gameBoard.getValidSpawnTile();
        }

        Save.saveBoard(gameBoard, r);
        Save.saveEntities(gameBoard, r);
        r.close();
      }

      File playerFile = new File(fileLocation + "/player.txt");
      playerFile.createNewFile();
      BufferedWriter w = new BufferedWriter(new FileWriter(playerFile));
      savePlayerProfession(w, p);
      Player pl = new Player(p, null);
      pl.setLocation(spawnTile, Tile.LAYER_ACTIVE);
      savePlayerStatus(w, pl);
      w.close();

      Save s = new Save(fileLocation);
      return s;
    } catch (IOException e) {
      throw new SlickException("unable to create save " + nameofSave, e);
    }
  }