Exemplo n.º 1
0
  public Map loadMap(File input) throws FileNotFoundException {
    Scanner s = new Scanner(input);
    tileDir = s.nextLine();
    int width = s.nextInt();
    int height = s.nextInt();
    Map toReturn = new Map(width, height, tileDir);
    s.nextLine(); // eat up rest of line.
    for (int y = 0; y < height; y++) {
      String line = s.nextLine();
      Scanner lineReader = new Scanner(line);
      List<Tile> tList = new ArrayList<Tile>();
      for (int x = 0; x < width; x++) {
        String[] values = lineReader.next().split("/");
        String name = values[0];
        int[] picLocation = new int[2];
        for (int i = 0; i < picLocation.length; i++) {
          picLocation[i] = Integer.parseInt(values[1].split("_")[i]);
        }
        ImageIcon img = null;
        try {
          img = new ImageIcon(getTile(tileDir, picLocation[0], picLocation[1], DISPLAY_SCALE));
        } catch (IOException e) {
          System.out.println("Could not find image.");
          img =
              new ImageIcon(
                  new BufferedImage(
                      TILE_SIZE * DISPLAY_SCALE,
                      TILE_SIZE * DISPLAY_SCALE,
                      BufferedImage.TYPE_INT_RGB));
        }
        int avoid = Integer.parseInt(values[2]);
        int def = Integer.parseInt(values[3]);
        String[] movString = values[4].split(",");
        int[] moveCost = new int[movString.length];
        for (int i = 0; i < moveCost.length; i++) {
          moveCost[i] = Integer.parseInt(movString[i]);
        }
        String special = values[5];

        Tile t =
            new Tile(
                img,
                name,
                avoid,
                def,
                moveCost,
                special,
                true,
                "" + picLocation[0] + "_" + picLocation[1]);
        tList.add(t);
        t.setMaximumSize(new Dimension(TILE_SIZE * DISPLAY_SCALE, TILE_SIZE * DISPLAY_SCALE));
        t.setPreferredSize(new Dimension(TILE_SIZE * DISPLAY_SCALE, TILE_SIZE * DISPLAY_SCALE));
        t.addMouseListener(new MapButtonListener());
      }
      toReturn.addRow(tList);
    }
    return toReturn;
  }
Exemplo n.º 2
0
 /**
  * Returns a map with the specified dimensions filled with the currTile image. The image should be
  * the upper-left tile of a given tileset if this is called from the constructor.
  */
 public Map emptyMap(int width, int height) {
   Map toReturn = new Map(width, height, tileDir);
   int[] mov = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
   for (int i = 0; i < height; i++) {
     List<Tile> tList = new ArrayList<Tile>();
     for (int j = 0; j < width; j++) {
       Tile t = new Tile(currTileImg, "Test", 0, 0, mov, "none", true, currTileLoc);
       tList.add(t);
       // t.setMargin(new Insets(0,0,0,0));
       t.setMaximumSize(new Dimension(TILE_SIZE * DISPLAY_SCALE, TILE_SIZE * DISPLAY_SCALE));
       t.setPreferredSize(new Dimension(TILE_SIZE * DISPLAY_SCALE, TILE_SIZE * DISPLAY_SCALE));
       // tile.setPreferredSize(new Dimension(TILE_SIZE*DISPLAY_SCALE, TILE_SIZE*DISPLAY_SCALE));
       t.addMouseListener(new MapButtonListener());
     }
     toReturn.addRow(tList);
   }
   return toReturn;
 }