Exemplo n.º 1
0
 public CellSet followCorner4(Cell cell, Cell blocked) {
   if (!isCorner4(cell)) return null;
   CellSet result = new CellSet();
   if (!cell.getNorth().equals(blocked)) result.add(cell.getNorth());
   if (!cell.getEast().equals(blocked)) result.add(cell.getEast());
   return result;
 }
Exemplo n.º 2
0
 public CellSet followStub(Cell cell, Cell blocked) {
   if (!isStub(cell)) return null;
   CellSet result = new CellSet();
   if (isBoundary(cell.getEast())) result.add(cell.getEast());
   else if (isBoundary(cell.getWest())) result.add(cell.getWest());
   else if (isBoundary(cell.getNorth())) result.add(cell.getNorth());
   else if (isBoundary(cell.getSouth())) result.add(cell.getSouth());
   if (result.contains(blocked)) result.remove(blocked);
   return result;
 }
Exemplo n.º 3
0
 /**
  * Returns the neighbours of a line-cell that are boundaries (0 to 2 cells are returned)
  *
  * @return null if the cell is not a line
  */
 public CellSet followLine(Cell cell) {
   if (isHorizontalLine(cell)) {
     CellSet result = new CellSet();
     if (isBoundary(cell.getEast())) result.add(cell.getEast());
     if (isBoundary(cell.getWest())) result.add(cell.getWest());
     return result;
   } else if (isVerticalLine(cell)) {
     CellSet result = new CellSet();
     if (isBoundary(cell.getNorth())) result.add(cell.getNorth());
     if (isBoundary(cell.getSouth())) result.add(cell.getSouth());
     return result;
   }
   return null;
 }
Exemplo n.º 4
0
  private CellSet seedFillOld(Cell seed, char newChar) {
    CellSet cellsFilled = new CellSet();
    char oldChar = get(seed);

    if (oldChar == newChar) return cellsFilled;
    if (isOutOfBounds(seed)) return cellsFilled;

    Stack<Cell> stack = new Stack<Cell>();

    stack.push(seed);

    while (!stack.isEmpty()) {
      Cell cell = stack.pop();

      set(cell, newChar);
      cellsFilled.add(cell);

      Cell nCell = cell.getNorth();
      Cell sCell = cell.getSouth();
      Cell eCell = cell.getEast();
      Cell wCell = cell.getWest();

      if (get(nCell) == oldChar) stack.push(nCell);
      if (get(sCell) == oldChar) stack.push(sCell);
      if (get(eCell) == oldChar) stack.push(eCell);
      if (get(wCell) == oldChar) stack.push(wCell);
    }

    return cellsFilled;
  }
Exemplo n.º 5
0
  public void replacePointMarkersOnLine() {
    int width = getWidth();
    int height = getHeight();
    for (int yi = 0; yi < height; yi++) {
      for (int xi = 0; xi < width; xi++) {
        char c = get(xi, yi);
        Cell cell = new Cell(xi, yi);
        if (StringUtils.isOneOf(c, pointMarkers) && isStarOnLine(cell)) {

          boolean isOnHorizontalLine = false;
          if (StringUtils.isOneOf(get(cell.getEast()), horizontalLines)) isOnHorizontalLine = true;
          if (StringUtils.isOneOf(get(cell.getWest()), horizontalLines)) isOnHorizontalLine = true;

          boolean isOnVerticalLine = false;
          if (StringUtils.isOneOf(get(cell.getNorth()), verticalLines)) isOnVerticalLine = true;
          if (StringUtils.isOneOf(get(cell.getSouth()), verticalLines)) isOnVerticalLine = true;

          if (isOnHorizontalLine && isOnVerticalLine) {
            set(xi, yi, '+');
            if (DEBUG) System.out.println("replaced marker on line '" + c + "' with +");
          } else if (isOnHorizontalLine) {
            set(xi, yi, '-');
            if (DEBUG) System.out.println("replaced marker on line '" + c + "' with -");
          } else if (isOnVerticalLine) {
            set(xi, yi, '|');
            if (DEBUG) System.out.println("replaced marker on line '" + c + "' with |");
          }
        }
      }
    }
  }
Exemplo n.º 6
0
 public CellSet followCrossOnLine(Cell cell, Cell blocked) {
   CellSet result = new CellSet();
   if (isHorizontalCrossOnLine(cell)) {
     result.add(cell.getEast());
     result.add(cell.getWest());
   } else if (isVerticalCrossOnLine(cell)) {
     result.add(cell.getNorth());
     result.add(cell.getSouth());
   }
   if (result.contains(blocked)) result.remove(blocked);
   return result;
 }
Exemplo n.º 7
0
 public CellSet followIntersection(Cell cell, Cell blocked) {
   if (!isIntersection(cell)) return null;
   CellSet result = new CellSet();
   Cell cN = cell.getNorth();
   Cell cS = cell.getSouth();
   Cell cE = cell.getEast();
   Cell cW = cell.getWest();
   if (hasEntryPoint(cN, 6)) result.add(cN);
   if (hasEntryPoint(cS, 2)) result.add(cS);
   if (hasEntryPoint(cE, 8)) result.add(cE);
   if (hasEntryPoint(cW, 4)) result.add(cW);
   if (result.contains(blocked)) result.remove(blocked);
   return result;
 }
Exemplo n.º 8
0
  private StackPane buildCell(Cell c) {

    // query the map object to find out information about cell
    // build out the stack pane for that cell based on this info
    // * surface type
    // * borders

    int north_border = c.getNorth();
    int east_border = c.getEast();
    int south_border = c.getSouth();
    int west_border = c.getWest();

    Region floor =
        generateFloorSurfacePane(c.getType(), north_border, east_border, south_border, west_border);
    Region closedDoor =
        generateClosedDoorPane(north_border, east_border, south_border, west_border);
    Region openDoor = generateOpenDoorPane(north_border, east_border, south_border, west_border);

    StackPane sp = new StackPane(closedDoor, openDoor, floor);
    sp.setBackground(
        new Background(new BackgroundFill(WALL_COLOR, CornerRadii.EMPTY, Insets.EMPTY)));
    return sp;
  }
Exemplo n.º 9
0
  /**
   * Locates and returns the '*' boundaries that we would encounter if we did a flood-fill at <code>
   * seed</code>.
   */
  public CellSet findBoundariesExpandingFrom(Cell seed) {
    CellSet boundaries = new CellSet();
    char oldChar = get(seed);

    if (isOutOfBounds(seed)) return boundaries;

    char newChar = 1; // TODO: kludge

    Stack<Cell> stack = new Stack<Cell>();

    stack.push(seed);

    while (!stack.isEmpty()) {
      Cell cell = stack.pop();

      set(cell, newChar);

      Cell nCell = cell.getNorth();
      Cell sCell = cell.getSouth();
      Cell eCell = cell.getEast();
      Cell wCell = cell.getWest();

      if (get(nCell) == oldChar) stack.push(nCell);
      else if (get(nCell) == '*') boundaries.add(nCell);

      if (get(sCell) == oldChar) stack.push(sCell);
      else if (get(sCell) == '*') boundaries.add(sCell);

      if (get(eCell) == oldChar) stack.push(eCell);
      else if (get(eCell) == '*') boundaries.add(eCell);

      if (get(wCell) == oldChar) stack.push(wCell);
      else if (get(wCell) == '*') boundaries.add(wCell);
    }

    return boundaries;
  }
Exemplo n.º 10
0
 public boolean isSouthArrowhead(Cell cell) {
   return (get(cell) == 'v' || get(cell) == 'V') && isVerticalLine(cell.getNorth());
 }