Ejemplo n.º 1
0
 private static void savePlayerStatus(BufferedWriter w, Player p) throws IOException {
   w.newLine();
   w.write(Integer.toString(p.getX()));
   w.newLine();
   w.write(Integer.toString(p.getY()));
   w.newLine();
   w.write(Integer.toString(p.EXP));
   w.newLine();
   w.write(Integer.toString(p.HP));
   w.newLine();
   w.write(Integer.toString(p.MP));
   w.newLine();
   w.write(InteractiveEntity.getInventoryAsString(p.getInventory(), p.inventorySize));
   w.newLine();
   w.write(InteractiveEntity.getInventoryAsString(p.getEquips(), p.inventorySize));
 }
Ejemplo n.º 2
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();
  }
Ejemplo n.º 3
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);
    }
  }
Ejemplo n.º 4
0
  private Player loadPlayerStatus(BufferedReader r, GameContainer c, GameBoard b, Profession p)
      throws SlickException, IOException {
    // TODO stuff
    r.readLine();
    int tileX = Integer.parseInt(r.readLine());
    int tileY = Integer.parseInt(r.readLine());
    int currentEXP = Integer.parseInt(r.readLine());
    int currentHP = Integer.parseInt(r.readLine());
    int currentMP = Integer.parseInt(r.readLine());
    ArrayList<Item> inventory = InteractiveEntity.loadItems(r.readLine().split(","));
    ArrayList<Item> equips = InteractiveEntity.loadItems(r.readLine().split(","));

    Player player = new Player(p, c.getInput());

    player.setLocation(b.getTileAt(tileX, tileY), Tile.LAYER_ACTIVE);
    player.EXP = currentEXP;
    player.HP = currentHP;
    player.MP = currentMP;
    player.getInventory().addAll(inventory);
    for (int i = 0; i < equips.size(); i++) {
      if (equips.get(i) != null) {
        player.equipItem((Equip) equips.get(i));
      }
    }

    return player;
  }
Ejemplo n.º 5
0
 private static void setPlayerPosition(Player player, GameBoard b, String lastMap) {
   // find the landing pad if it's coming from the old map. Otherwise, use the player's coords
   if (!lastMap.equals("")) {
     Tile target = null;
     for (int x = 0; x < b.getWidth(); x++) {
       for (int y = 0; y < b.getHeight(); y++) {
         if (!b.getTileAt(x, y).isOpen(Tile.LAYER_PASSIVE_MAP)) {
           if (LandingPad.class.isAssignableFrom(
               b.getTileAt(x, y).getEntity(Tile.LAYER_PASSIVE_MAP).getClass())) {
             LandingPad pad =
                 LandingPad.class.cast(b.getTileAt(x, y).getEntity(Tile.LAYER_PASSIVE_MAP));
             if (pad.fromFloor.equals(lastMap)) {
               target = b.getTileAt(x, y);
               break;
             }
           }
         }
       }
     }
     b.insertEntity(0, target, player, Tile.LAYER_ACTIVE);
   } else {
     b.insertEntity(0, b.getTileAt(player.getX(), player.getY()), player, Tile.LAYER_ACTIVE);
   }
 }