Exemple #1
0
        private void Build_Click(object sender, EventArgs e)
        {
            int startX = Convert.ToInt32(startBoxX.Text);
            int startY = Convert.ToInt32(startBoxY.Text);
            int endX   = Convert.ToInt32(endBoxX.Text);
            int endY   = Convert.ToInt32(endBoxY.Text);

            width  = Math.Abs(endX - startX);
            height = Math.Abs(endY - startY);

            findPathButton.Enabled = true;

            allLocations = new LocationMap();
            int mapWidth  = map.Width;
            int mapHeight = map.Height;

            map.Controls.Clear();

            for (int w = 0; w < width; w++)
            {
                for (int h = 0; h < height; h++)
                {
                    int   x         = 50 + mapWidth / width * w;
                    int   y         = 50 + mapHeight / height * h;
                    Point nextPoint = new Point(x, y);

                    Location toAdd      = new Location(nextPoint);
                    int      difficulty = toAdd.difficulty;
                    allLocations.Add(toAdd);

                    Label terrain = new Label();
                    terrain.BringToFront();
                    terrain.Text     = difficulty.ToString();
                    terrain.AutoSize = true;

                    int labelWidth  = terrain.Width;
                    int labelHeight = terrain.Height;

                    terrain.Location = nextPoint;

                    map.Controls.Add(terrain);
                }
            }

            allLocations.SetStartAndEnd();
        }
Exemple #2
0
        public List <Point> findBestPath(LocationMap allLocations)
        {
            Point startPoint = allLocations.start.position;

            endPoint = allLocations.end.position;

            int vertical   = Path.GetVerticalDirection(startPoint, endPoint);
            int horizontal = Path.GetHorizontalDirection(startPoint, endPoint);

            Path   pathA   = new Path(this, null, vertical);
            Path   pathB   = new Path(this, null, horizontal);
            Thread threadA = new Thread(new ThreadStart(pathA.findPath));

            threadA.Join();
            Thread threadB = new Thread(new ThreadStart(pathB.findPath));

            threadB.Join();

            List <Point> bestPath = new List <Point>();

            return(bestPath);
        }