@Override
 public String toString() {
   StringBuilder sb = new StringBuilder();
   for (Tile t : this.map.values()) {
     sb.append("x: " + t.getPoint().x);
     sb.append("y: " + t.getPoint().y);
     sb.append(" obs: " + t.isObstacle());
     sb.append(" dirty: " + t.isDirty());
     sb.append(" base: " + t.isBase());
     sb.append("\n");
   }
   return sb.toString();
 }
示例#2
0
 @Override
 public void take() {
   super.take();
   _gameScreen.setMap(_eventPath, _newX, _newY);
   _tile.removeOccupant();
   _gameScreen.popControl();
 }
  private void updateMinMax(Tile t) {
    if (t.isObstacle()) return;

    if (!rowsWallsDetected) {
      if (t.getPoint().x < minX) minX = t.getPoint().x;
      if (t.getPoint().x > maxX) maxX = t.getPoint().x;
    }
    if (!colsWallsDetected) {
      if (t.getPoint().y < minY) minY = t.getPoint().y;

      if (t.getPoint().y > maxY) maxY = t.getPoint().y;
    }
  }
示例#4
0
 public static Map load(File f) throws IOException {
   List<Tile[]> tilesList = new ArrayList<>();
   try (BufferedReader in = new BufferedReader(new FileReader(f))) {
     String line;
     while ((line = in.readLine()) != null) {
       String[] tileStrings = line.split(SEPARATOR);
       Tile[] row = new Tile[tileStrings.length];
       for (int i = 0; i < row.length; i++) {
         row[i] = Tile.decode(tileStrings[i]);
       }
       tilesList.add(row);
     }
     Tile[][] tiles = new Tile[tilesList.size()][tilesList.get(0).length];
     for (int y = 0; y < tiles.length; y++) {
       for (int x = 0; x < tiles[y].length; x++) {
         tiles[y][x] = tilesList.get(y)[x];
       }
     }
     return new Map(tiles);
   }
 }
 public boolean isVisited(Tile t) {
   return this.map.containsKey(t.getPoint());
 }
 private void setBase(Tile t) {
   if (!t.isBase()) {
     // TODO error
   }
   this.base = t;
 }
  public void setTile(Tile t) {
    updateMinMax(t);

    /* TODO check, will hashCode of points works? */
    this.map.put(t.getPoint(), t);
  }
 public boolean isDirty(Point p) {
   Tile t = getTile(p);
   if (t == null) return false;
   return t.isDirty();
 }
  public boolean isWall(Tile t) {
    if (this.isVisited(t)) return this.map.get(t.getPoint()).isWall();

    return false;
  }