import java.util.*;

/**
 * A map of the tunnel system.
 */

public class Map
{
    public Map (Vector<String> input, boolean debug)
    {
        _theMap = new Vector<Cell>();
        _debug = debug;

        createMap(input);
    }

    public Coordinate getEntrance ()
    {
        Enumeration<Cell> iter = _theMap.elements();

        while (iter.hasMoreElements())
        {
            Cell theCell = iter.nextElement();

            if (theCell.isEntrance())
                return theCell.position();
        }

        return null;  // oops!! shouldn't happen.
    }

    @Override
    public String toString ()
    {
        Enumeration<Cell> iter = _theMap.elements();
        int index = 1;
        String str = "Map <"+_maxX+", "+_maxY+">:\n\n";

        while (iter.hasMoreElements())
        {
            str += iter.nextElement().getContents();

            if (index++ == _maxX)
            {
                str += "\n";

                index = 1;
            }
        }

        return str;
    }

    // create the map from input
    
    private void createMap (Vector<String> input)
    {
        Enumeration<String> iter = input.elements();
        int y = -1;

        _maxX = input.get(0).length(); // all lines are the same length

        while (iter.hasMoreElements())
        {
            y++;

            String line = iter.nextElement();

            for (int x = 0; x < _maxX; x++)
            {
                Cell theCell = new Cell(new Coordinate(x, y), line.charAt(x), _debug);

                if (theCell.isEntrance())
                    _entrance = theCell.position();  // should be only one!

                if (_debug)
                    System.out.println(theCell);

                _theMap.add(theCell);
            }
        }

        _maxY = y+1;
    }

    // from the map create a graph

    public void createGraph ()  // temporary public for testing!
    {
        Node[][] nodeMap = new Node[_maxX][_maxY];
        Enumeration<Cell> iter = _theMap.elements();
        int x = 0;
        int y = 0;

        while (iter.hasMoreElements())
        {
            nodeMap[x][y] = new Node(iter.nextElement());

            x++;

            if (x == _maxX)
            {
                x = 0;
                y++;
            }
        }

        for (int i = 0; i < _maxX; i++)
        {
            for (int j = 0; j < _maxY; j++)
            {
                Node up = null;
                Node down = null;
                Node left = null;
                Node right = null;

                if (i -1 >= 0)
                    left = nodeMap[i-1][j];
                
                if (i +1 < _maxX)
                    right = nodeMap[i +1][j];

                if (j -1 >= 0)
                    up = nodeMap[i][j -1];

                if (j +1 < _maxY)
                    down = nodeMap[i][j +1];

                nodeMap[i][j].setLinks(up, down, left, right);
            }
        }

        for (x = 0; x < _maxX; x++)
        {
            for (y = 0; y < _maxY; y++)
            {
                System.out.println("\n"+nodeMap[x][y]);
            }
        }
    }

    private Vector<Cell> _theMap;
    private int _maxX;
    private int _maxY;
    private Coordinate _entrance;
    private boolean _debug;
}
@@ -166,24 +166,49 @@
 or%3CCell%3E();%0A
+        _nodeMap = null;%0A
         _deb
@@ -308,292 +308,25 @@
     
-Enumeration%3CCell%3E iter = _theMap.elements();%0A%0A        while (iter.hasMoreElements())%0A        %7B%0A            Cell theCell = iter.nextElement();%0A%0A            if (theCell.isEntrance())%0A                return theCell.position();%0A        %7D%0A%0A        return null;  // oops!! shouldn't happen.
+return _entrance;
 %0A   
@@ -1605,19 +1605,12 @@
     
-public void
+Node
  cre
@@ -1665,59 +1665,8 @@
   %7B%0A
-        Node%5B%5D%5B%5D nodeMap = new Node%5B_maxX%5D%5B_maxY%5D;%0A
     
@@ -1753,16 +1753,60 @@
 y = 0;%0A%0A
+        _nodeMap = new Node%5B_maxX%5D%5B_maxY%5D;%0A%0A
         
@@ -1850,32 +1850,33 @@
   %7B%0A            
+_
 nodeMap%5Bx%5D%5By%5D = 
@@ -2333,24 +2333,25 @@
      left = 
+_
 nodeMap%5Bi-1%5D
@@ -2434,16 +2434,17 @@
 right = 
+_
 nodeMap%5B
@@ -2510,16 +2510,17 @@
    up = 
+_
 nodeMap%5B
@@ -2591,16 +2591,17 @@
  down = 
+_
 nodeMap%5B
@@ -2627,16 +2627,17 @@
         
+_
 nodeMap%5B
@@ -2692,32 +2692,66 @@
    %7D%0A        %7D%0A%0A
+        if (_debug)%0A        %7B%0A    
         for (x =
@@ -2762,32 +2762,36 @@
 x %3C _maxX; x++)%0A
+    
         %7B%0A      
@@ -2792,24 +2792,28 @@
             
+    
 for (y = 0; 
@@ -2832,34 +2832,41 @@
 ++)%0A            
-%7B%0A
+    %7B%0A   
                 
@@ -2857,32 +2857,33 @@
                 
+ 
 System.out.print
@@ -2890,16 +2890,17 @@
 ln(%22%5Cn%22+
+_
 nodeMap%5B
@@ -2911,34 +2911,42 @@
 %5D);%0A            
+   
+ 
 %7D%0A
+    
         %7D%0A    %7D%0A
@@ -2947,39 +2947,142 @@
     
-%7D%0A%0A    private Vector%3CCell%3E _th
+    %7D%0A%0A        return _nodeMap%5B_entrance.getX()%5D%5B_entrance.getY()%5D;%0A    %7D%0A%0A    private Vector%3CCell%3E _theMap;%0A    private Node%5B%5D%5B%5D _nod
 eMap

Update Map.java