Witam,
Jestem początkującym programistą więc proszę o wyrozumiałość.
Próbuję napisać rekurencję rysującą obiekty Element.
Każdy element może mieć dziecko (lecz nie musi) i posiadając dziecko jest parentem.
Każde dziecko może mieć swoje dzieci i być parentem itd...
Element reprezentowany jest przez kwadrat. Rodzeństwo jest wyświetlane obok siebie z przesunięciem względem swojej pozycji XY.
Na chwile obecną chyba przepełniam pamięć :/
KOD:
//BASE_BAR_SIZE = 100;
//Brush deviceBrush = new SolidBrush(Color.Blue);
private void DrawElements(int child,PaintEventArgs e)
{
Element oNode = new Element(0, 0, child);
for (int i = 1; i <= oNode.cChildren;) //Draws this node children
{
e.Graphics.FillRectangle(deviceBrush,(BASE_BAR_SIZE * oNode.positionX)+20,(BASE_BAR_SIZE * oNode.positionY)+20, 60, 60);
oNode.positionX += 1;
i++;
}
DrawElements(oNode.cChildren--,e);
}
KLASA ELEMENT:
class Element
{
public int positionX;
public int positionY;
public int cChildren;
public Element()
{
}
public Element(int x,int y,int child)
{
this.positionX = x;
this.positionY = y;
this.cChildren = child;
}
private bool isParent()
{
if (this.cChildren > 0)
return true;
else return false;
}
}
Poproszę o sugestie i krytykę.