示例#1
0
 /**
  * Converts map data from String to ArrayList<Point>, which represents warp points. Note: "Warp
  * points" means the places to warp TO, not FROM. These points specify destinations to OTHER maps,
  * not the current one.
  *
  * @param contents : String data from file.
  * @param warpPoints : ArrayList to store points.
  * @return : Leftover String data, or empty string "" if no data follows.
  */
 public static String readMapData4(String contents, ArrayList<Point> warpPoints) throws Exception {
   try {
     int delimiter = breakPoint(contents, 1, '\n');
     String line = contents.substring(0, delimiter - 1);
     if (contents.length() > delimiter + 1) {
       contents = contents.substring(delimiter + 1);
     } else {
       contents = "";
     }
     if (line.equals("null")) {
       return contents;
     }
     for (int index = 0; index < line.length(); ++index) {
       int delimit = breakPoint(line, 1, ' ');
       if (delimit == -1) {
         break;
       }
       warpPoints.add(strToPoint(line.substring(0, delimit)));
       line = line.substring(delimit + 1);
     }
     warpPoints.add(strToPoint(line));
     MapMaker.setMapData4(warpPoints);
     return contents;
   } catch (Exception e) {
     e.printStackTrace();
     throw new Exception("Cannot read warp point data.");
   }
 }
示例#2
0
  /**
   * Converts map data from String to <code>double[][][]</code>, where the array's first brackets
   * represent layers.
   *
   * @param contents : String data from file.
   * @param mapSet : Array of map data (first three layers).
   * @return : Leftover String data.
   */
  public static String readMapData1(String contents) throws Exception {
    // TODO These methods are poorly named! Change them!! :(
    try {
      int count = 0;
      while (contents.charAt(count) != '\n') {
        ++count;
      }
      Point pt = strToPoint(contents.substring(0, count));
      contents = contents.substring(count + 1);
      int x = (int) pt.getX(), y = (int) pt.getY();

      double[][][] mapSet = new double[3][x][y];
      // Uses a process/chop method on contents
      int delimit = breakPoint(contents, y, '\n');
      mapSet[0] = processDoubleArray(x, y, contents.substring(0, delimit));
      contents = contents.substring(delimit + 1);
      delimit = breakPoint(contents, y, '\n');
      mapSet[1] = processDoubleArray(x, y, contents);
      contents = contents.substring(delimit + 1);
      delimit = breakPoint(contents, y, '\n');
      mapSet[2] = processDoubleArray(x, y, contents);
      contents = contents.substring(delimit + 1);
      MapMaker.setMapData1(mapSet);
      return contents;
    } catch (Exception e) {
      e.printStackTrace();
      throw new Exception("Cannot read basic layers data.");
    }
  }
示例#3
0
 /**
  * Converts map data from String to int[][], which represents warp data.
  *
  * @param contents : String data from file.
  * @param warpMap : Array to store warp data.
  * @return : Leftover String data.
  */
 public static String readMapData2(String contents, int[][] warpMap) throws Exception {
   try {
     int x = warpMap.length, y = warpMap[0].length;
     int delimit = breakPoint(contents, y, '\n');
     warpMap = processIntArray(x, y, contents.substring(0, delimit - 1));
     contents = contents.substring(delimit + 1);
     MapMaker.setMapData2(warpMap);
     return contents;
   } catch (Exception e) {
     e.printStackTrace();
     throw new Exception("Cannot read warp layer data.");
   }
 }
示例#4
0
 /**
  * Converts map data from String to ArrayList<String>, which represents warp map names.
  *
  * @param contents : String data from file.
  * @param warpNames : ArrayList to store names.
  * @return : Leftover String data.
  */
 public static String readMapData3(String contents, ArrayList<String> warpNames) throws Exception {
   try {
     int delimit = breakPoint(contents, 1, '\n');
     String line = contents.substring(0, delimit - 1);
     contents = contents.substring(delimit + 1);
     if (line.equals("null")) {
       return contents;
     }
     int start = 0;
     for (int index = 0; index < line.length(); ++index) {
       if (line.charAt(index) == ' ') {
         warpNames.add(line.substring(start, index));
         start = index + 1;
       }
     }
     warpNames.add(line.substring(start));
     MapMaker.setMapData3(warpNames);
     return contents;
   } catch (Exception e) {
     e.printStackTrace();
     throw new Exception("Cannot read warp name data.");
   }
 }