PIBD-14_Boyko_M_S_Cursach_DFS/Cursach/Visualizator.cs
2024-05-22 20:29:11 +04:00

40 lines
1.3 KiB
C#

using Cursach.Realisations;
using Cursach.States;
namespace Cursach;
// Can do this class static
public class Visualizator
{
public void Draw(Graphics g, State state)
{
Pen penLine = new(Color.Black, 5);
Brush darkBrush = new SolidBrush(Color.Black);
g.FillRectangle(new SolidBrush(Color.White), 0, 0, 500, 500);
AdjacencyList _adjacencyList = state.AdjacencyList;
foreach (var parentNode in _adjacencyList.Keys())
{
foreach (var childNode in _adjacencyList.Values(parentNode))
{
g.DrawLine(penLine, parentNode.GetPosition(), childNode.GetPosition());
}
g.DrawString(parentNode.ToString(), new Font("Comic Sans MS", 7), darkBrush,
parentNode.GetPosition().X - 20, parentNode.GetPosition().Y - 30);
if (state.visited.Contains(parentNode))
{
VizulizatorGraph.DrawPoint(g, parentNode.GetPosition(), Color.Crimson);
}
else if (state.queue.Contains(parentNode))
{
VizulizatorGraph.DrawPoint(g, parentNode.GetPosition(), Color.DarkSlateGray);
}
else
{
VizulizatorGraph.DrawPoint(g, parentNode.GetPosition(), Color.Gray);
}
}
}
}