PIBD-14_Boyko_M_S_Cursach_DFS/Cursach/Visualizator.cs

43 lines
1.4 KiB
C#
Raw Normal View History

2024-05-16 00:37:58 +04:00
using Cursach.Realisations;
using Cursach.States;
namespace Cursach;
public class Visualizator
{
private State? State { get; set; }
public void Draw(Graphics g, State state)
{
Pen penLine = new(Color.Black, 5);
Pen penBid = new(Color.Red, 2);
Pen penSelectedBid = new(Color.Green, 3);
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);
}
}
}
}