Beispiel #1
0
        public GridGraph(int[,] data)
        {
            this.nodes  = new List <GridNode>(); //Creates a new list of nodes
            this.width  = data.GetLength(0);     //Sets the width
            this.height = data.GetLength(1);     //Sets the height

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    this.nodes.Add(new GridNode(new Vector2(x, y), data[x, y])); //Creates a node for each position
                }
            }

            //Neighbours
            foreach (GridNode NodeA in this.nodes)                                                                                     //Runs through each node
            {
                foreach (GridNode NodeB in this.nodes)                                                                                 //Runs through every other node
                {
                    NodeA.SetNeighbour(NodeB, (int)(NodeB.Location.X - NodeA.Location.X), (int)(NodeB.Location.Y - NodeA.Location.Y)); //Evaluates to see if they are neighbours
                }
            }
        }
Beispiel #2
0
        public GridGraph(int[,] data)
        {
            this.nodes  = new List <GridNode>();
            this.width  = data.GetLength(0);
            this.height = data.GetLength(1);

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    this.nodes.Add(new GridNode(new Vector2(x, y), data[x, y]));
                }
            }

            //Neighbours
            foreach (GridNode NodeA in this.nodes)
            {
                foreach (GridNode NodeB in this.nodes)
                {
                    NodeA.SetNeighbour(NodeB, NodeB.Location.X - NodeA.Location.X, NodeB.Location.Y - NodeA.Location.Y);
                }
            }
        }