105 lines
2.4 KiB
C#
105 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace DobozFeladat
|
|
{
|
|
public class Box
|
|
{
|
|
public char Type { get; set; }
|
|
public bool IsDefected = false;
|
|
public Box Parent = null;
|
|
public Box Child = null;
|
|
|
|
public Box(char Type)
|
|
{
|
|
this.Type = Type;
|
|
}
|
|
|
|
public Box(char Type, bool IsDefected)
|
|
{
|
|
this.Type = Type;
|
|
this.IsDefected = IsDefected;
|
|
}
|
|
|
|
public bool AddedChild(Box newbox)
|
|
{
|
|
if (this.IsDefected)
|
|
{
|
|
if (this.Type == 'A' && newbox.Type == 'C')
|
|
{
|
|
SetChildParentProperties(newbox);
|
|
return true;
|
|
}
|
|
|
|
if (this.Type == 'B')
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if (this.Child == null)
|
|
{
|
|
if (this.Type == 'A' && (newbox.Type == 'B' || newbox.Type == 'C'))
|
|
{
|
|
SetChildParentProperties(newbox);
|
|
return true;
|
|
}
|
|
|
|
if (this.Type == 'B' && newbox.Type == 'C')
|
|
{
|
|
SetChildParentProperties(newbox);
|
|
return true;
|
|
}
|
|
} else
|
|
{
|
|
return this.Child.AddedChild(newbox);
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
public void SetChildParentProperties(Box newbox)
|
|
{
|
|
this.Child = newbox;
|
|
newbox.Parent = this;
|
|
}
|
|
|
|
public bool ReadyForPackaging()
|
|
{
|
|
if (this.Child != null)
|
|
{
|
|
return this.Child.ReadyForPackaging();
|
|
}
|
|
|
|
if (this.Type == 'B' && this.IsDefected)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
if (this.Type == 'C')
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public string PrintBoxRecursively()
|
|
{
|
|
if (this.Child != null)
|
|
{
|
|
Console.Write(this.Type);
|
|
return this.Child.PrintBoxRecursively();
|
|
}
|
|
Console.WriteLine(this.Type);
|
|
return $"{this.Type}";
|
|
}
|
|
}
|
|
}
|