Esempio n. 1
0
 public void drawABox(int width, int height) {
   LayoutNode n = new DefaultLayoutNode(new long[] {0, 0});
   n.flag(LayoutFlags.corner);
   for (int y = 0; y < height - 1; y++) {
     use(n, LayoutTypes.surround);
     LayoutNode nn = getNextNode(n, Directions.NORTH);
     if (nn == null) nn = makeNextNode(n, Directions.NORTH);
     n.crossLink(nn);
     nn.flagRun(LayoutRuns.ns);
     n = nn;
   }
   n.flag(LayoutFlags.corner);
   use(n, LayoutTypes.surround);
   n = new DefaultLayoutNode(new long[] {width - 1, 0});
   n.flag(LayoutFlags.corner);
   for (int y = 0; y < height - 1; y++) {
     use(n, LayoutTypes.surround);
     LayoutNode nn = getNextNode(n, Directions.NORTH);
     if (nn == null) nn = makeNextNode(n, Directions.NORTH);
     n.crossLink(nn);
     nn.flagRun(LayoutRuns.ns);
     n = nn;
   }
   n.flag(LayoutFlags.corner);
   use(n, LayoutTypes.surround);
   n = getNode(new long[] {0, 0});
   n.flag(LayoutFlags.corner);
   for (int x = 0; x < width - 1; x++) {
     use(n, LayoutTypes.surround);
     LayoutNode nn = getNextNode(n, Directions.EAST);
     if (nn == null) nn = makeNextNode(n, Directions.EAST);
     n.crossLink(nn);
     nn.flagRun(LayoutRuns.ns);
     n = nn;
   }
   n.flag(LayoutFlags.corner);
   use(n, LayoutTypes.surround);
   n = getNode(new long[] {0, -height + 1});
   n.flag(LayoutFlags.corner);
   for (int x = 0; x < width - 1; x++) {
     use(n, LayoutTypes.surround);
     LayoutNode nn = getNextNode(n, Directions.EAST);
     if (nn == null) nn = makeNextNode(n, Directions.EAST);
     n.crossLink(nn);
     nn.flagRun(LayoutRuns.ns);
     n = nn;
   }
   n.flag(LayoutFlags.corner);
   use(n, LayoutTypes.surround);
 }
Esempio n. 2
0
 public void clipLongStreets() {
   @SuppressWarnings("unchecked")
   Vector<LayoutNode> set2 = (Vector<LayoutNode>) set().clone();
   for (Enumeration<LayoutNode> e = set2.elements(); e.hasMoreElements(); ) {
     LayoutNode p = e.nextElement();
     if (isUsed(p) && p.isStreetLike())
       for (int d = 0; d < 4; d++)
         if (p.getLink(d) == null) {
           LayoutNode p2 = getNextNode(p, d);
           if ((p2 != null) && (!p.links().containsValue(p2))) {
             Enumeration<LayoutNode> nodes = p.links().elements();
             LayoutNode p_1 = nodes.nextElement();
             LayoutNode p_2 = nodes.nextElement();
             p.deLink();
             p_1.crossLink(p_2);
             unUse(p);
             LayoutNode p3 = makeNextNode(p2, Directions.getOpDirectionCode(d));
             p2.crossLink(p3);
             use(p3, LayoutTypes.leaf);
             break;
           }
         }
   }
 }
Esempio n. 3
0
 public boolean fillMaze(LayoutNode p) {
   Vector<Integer> dirs = new Vector<Integer>();
   for (int i = 0; i < 4; i++) dirs.add(Integer.valueOf(i));
   Vector<Integer> rdirs = new Vector<Integer>();
   while (dirs.size() > 0) {
     int x = r.nextInt(dirs.size());
     Integer dir = dirs.elementAt(x);
     dirs.removeElementAt(x);
     rdirs.addElement(dir);
   }
   for (int r = 0; r < rdirs.size(); r++) {
     Integer dir = rdirs.elementAt(r);
     LayoutNode p2 = getNextNode(p, dir.intValue());
     if (p2 == null) {
       p2 = makeNextNode(p, dir.intValue());
       p.crossLink(p2);
       use(p2, LayoutTypes.interior);
       fillMaze(p2);
     }
   }
   return true;
 }