Beispiel #1
0
        private void PictureBox_Paint(object sender, PaintEventArgs e)
        {
            if (rbSquares.Checked)
            {
                DrawGrid(e);

                // draw spots from the open set
                if (mapPathFinder.OpenCount > 0)
                {
                    for (int i = 0; i < mapPathFinder.OpenCount; i++)
                    {
                        DrawSpot(mapPathFinder.Open(i), Color.Green, e);
                    }
                }

                // draw spots from the closed set
                if (mapPathFinder.ClosedCount > 0)
                {
                    for (int i = 0; i < mapPathFinder.ClosedCount; i++)
                    {
                        DrawSpot(mapPathFinder.Closed(i), Color.Red, e);
                    }
                }
            }

            if (rbSquares.Checked)
            {
                // draw the path
                for (int i = 0; i < mapPathFinder.path.Count; i++)
                {
                    DrawSpot(mapPathFinder.path[i], Color.Blue, e);
                }
            }
            else
            {
                // draw the path
                for (int i = 0; i < mapPathFinder.path.Count - 1; i++)
                {
                    DrawLine(mapPathFinder.path[i], mapPathFinder.path[i + 1], e);
                }
            }

            // draw the obstacles
            var obstacles = map.grid.FindAll(x => x.isObstacle == true);

            foreach (Spot obstacle in obstacles)
            {
                DrawSpot(obstacle, Color.Black, e);
            }

            if (map.HasHighlightedCell)
            {
                Spot highlight = new Spot(map.highlightRow, map.highlightColumn);
                DrawSpot(highlight, Color.Yellow, e);
            }
        }