예제 #1
0
 @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();
 }
예제 #3
0
  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);
   }
 }
예제 #5
0
 public boolean isVisited(Tile t) {
   return this.map.containsKey(t.getPoint());
 }
예제 #6
0
 private void setBase(Tile t) {
   if (!t.isBase()) {
     // TODO error
   }
   this.base = t;
 }
예제 #7
0
  public void setTile(Tile t) {
    updateMinMax(t);

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

    return false;
  }