Пример #1
0
        public static Graph <Vector2> GenerateGraph(float totalWidth, float totalHeight,
                                                    int xAxisVertexCount, int yAxisVertexCount,
                                                    float xOffset, float yOffset,
                                                    NeighbourGenerator neighbourGenerator)
        {
            float vectorXDistance = totalWidth / (xAxisVertexCount - 1);
            float vectorYDistance = totalHeight / (yAxisVertexCount - 1);

            Graph <Vector2> returnGraph = new Graph <Vector2>();

            int index = 0;

            for (int y = 0; y < yAxisVertexCount; y++)
            {
                for (int x = 0; x < xAxisVertexCount; x++)
                {
                    Vector2 vector = new Vector2
                    {
                        X = xOffset + vectorXDistance * x,
                        Y = yOffset + vectorYDistance * y
                    };

                    Vertex <Vector2> vertex = returnGraph.GetVertex(index);
                    vertex.Value = vector;

                    foreach ((int neighbourIndex, float cost) in neighbourGenerator(x, y, xAxisVertexCount, yAxisVertexCount, vectorXDistance, vectorYDistance))
                    {
                        returnGraph.AddEdge(index, neighbourIndex, cost);
                    }

                    index++;
                }
            }

            return(returnGraph);
        }
Пример #2
0
        public static Graph <Vector2> CreateGridGraph_Base(int width, int height, NeighbourGenerator neighbourGetter)
        {
            Graph <Vector2> graph = new Graph <Vector2>();

            int index = 0;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    Vertex <Vector2> vertex = graph.GetVertex(index + 1);
                    vertex.Value = new Vector2(x, y);

                    foreach ((int neighbourIndex, float cost) in neighbourGetter(x, y, width, height, 1, 1))
                    {
                        graph.AddEdge(index + 1, neighbourIndex, cost);
                    }

                    index++;
                }
            }

            return(graph);
        }
Пример #3
0
 public GameWorld()
 {
     _surroundingCellLocations  = new NeighbourGenerator();
     CellLocationsOfLivingCells = new Dictionary <string, CellLocation>();
 }