added another Doboz implementation
This commit is contained in:
104
fordulo_3/Doboz/DobozFeladat/Box.cs
Normal file
104
fordulo_3/Doboz/DobozFeladat/Box.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
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}";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user