예제 #1
0
        private void init()
        {
            //this.UpdateStatus(Status.Starting());
            int total = Width * Height;

            graph = new  MazeGraph(false, total, 4);

            matrix = new MazeNode[Width, Height];

            //create the nodes
            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    matrix[x, y] = new MazeNode(x + (y * Width), NodeType.Floor);
                    graph.AddVertex(matrix[x, y]);
                }
                //this.UpdateStatus(Status.UpdateLoopMessage("Creating nodes", x, Width));
            }

            //populate the edges
            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    /*
                     * if (x == 0)
                     * {
                     *  matrix[x, y].LeftEdge = new MazeEdge(matrix[x, y], null);
                     * }
                     * if (y == 0)
                     * {
                     *  matrix[x, y].TopEdge = new MazeEdge(matrix[x, y], null);
                     * }
                     * if (x == (Width - 1))
                     * {
                     *  matrix[x, y].RightEdge = new MazeEdge(matrix[x, y], null);
                     * }
                     * if (y == (Height - 1))
                     * {
                     *  matrix[x, y].BottomEdge = new MazeEdge(matrix[x, y], null);
                     * }*/


                    if (x > 0)
                    {
                        //matrix[x, y].LeftEdge = new MazeEdge(matrix[x, y], matrix[x - 1, y]);
                        //graph.AddEdge(matrix[x, y].LeftEdge);

                        matrix[x, y].LeftEdge = matrix[x - 1, y].RightEdge;
                    }
                    if (y > 0)
                    {
                        //matrix[x, y].TopEdge = new MazeEdge(matrix[x, y], matrix[x, y - 1]);
                        //graph.AddEdge(matrix[x, y].TopEdge);

                        matrix[x, y].TopEdge = matrix[x, y - 1].BottomEdge;
                    }
                    if (x < (Width - 1))
                    {
                        matrix[x, y].RightEdge = new MazeEdge(matrix[x, y], matrix[x + 1, y]);
                        graph.AddEdge(matrix[x, y].RightEdge);
                    }
                    if (y < (Height - 1))
                    {
                        matrix[x, y].BottomEdge = new MazeEdge(matrix[x, y], matrix[x, y + 1]);
                        graph.AddEdge(matrix[x, y].BottomEdge);
                    }
                }
                //this.UpdateStatus(Status.UpdateLoopMessage("Populating edges", x, Width));
            }

            //this.UpdateStatus(Status.Done());
        }