Exemplo n.º 1
0
        public Form1()
        {
            InitializeComponent();
            int[,] biomeMap;
            var popCenters = buildData(out biomeMap);
            var field      = new TerrainType()
            {
                cost = 10f,
                name = "field"
            };
            var wood = new TerrainType()
            {
                cost = 2f,
                name = "wood"
            };
            var town = new TerrainType()
            {
                cost = 1.5f,
                name = "town"
            };
            World world = new World(biomeMap, new List <TerrainType>()
            {
                field, wood, town
            });

            Console.WriteLine("built world");
            pathfinding = world.getPathSolver();
            Console.WriteLine("built pathFinding");
            //pictureBox.Image = world.image;
            //pictureBox.Image=world.();
            var road = new RoadType()
            {
                weightRequirement = 0,
                cost = 1f
            };
            var highway = new RoadType()
            {
                weightRequirement = 5f,
                cost = 1f
            };
            var roads = new List <RoadType> {
                road, highway
            };
            var popCenter1 = new PopulationCentre(new MyMath.Point(10, 10), 100);
            var popCenter2 = new PopulationCentre(new MyMath.Point(74, 3), 30);
            var popCenter3 = new PopulationCentre(new MyMath.Point(230, 100), 70);
            var popCenter4 = new PopulationCentre(new MyMath.Point(200, 250), 30);
            var pops       = new List <PopulationCentre>()
            {
                popCenter1, popCenter3, popCenter4
            };

            pathfinding.AddRoads(popCenters, roads);

            //var path = pathfinding.getPath(new MyMath.Point(3, 3), new MyMath.Point(95, 53));
            var g = Graphics.FromImage(pictureBox.Image);

            foreach (var segment in pathfinding.roadNetwork.roadSegments)
            {
                Color c = Color.Gray;
                if ((segment.roadType as RoadType).weightRequirement != 0)
                {
                    c = Color.Purple;
                }
                g.DrawLines(new Pen(c, 1), segment.ConvertAll(x => new PointF(x.x, x.y)).ToArray());
            }
            pictureBox.Image.Save("roadMap.png");
            var meshes = world.getMeshes();

            /*foreach(var v in pathfinding.navigationNodes())
             * {
             *
             *      g.FillRectangle(new SolidBrush(Color.Red), (float)v.x, (float)v.y, 1, 1);
             *
             * }*/
        }