Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Sephiroth
- {
- static Sephiroth instance;
- static Random Ran = new Random();
- public static Sephiroth Instance
- {
- get
- {
- if (instance == null)
- instance = new Sephiroth(0);
- return instance;
- }
- }
- public Sephiroth(int id)
- {
- Key = id;
- Root.Add(Key, this);
- Baby.Add(Key, this);
- Baby = new Dictionary<int, object>();
- Root = new Dictionary<int, object>();
- }
- public int Key { get; set; }
- public Sephiroth Mother { get; set; }
- public string Name { get; set; } = string.Empty;
- public bool IsSurvival
- {
- get
- {
- return Root.ContainsKey(Key);
- }
- }
- public Dictionary<int, object> Baby;
- public Dictionary<int, object> Root;
- public Dictionary<int, object> Children => new Dictionary<int, object>();
- public Sephiroth Pregnant()
- {
- Sephiroth element;
- while (true)
- {
- int key = Ran.Next();
- if (!Baby.ContainsKey(key))
- {
- element = new Sephiroth(key);
- element.Mother = this;
- Baby.Add(key, element);
- break;
- }
- }
- return element;
- }
- public IEnumerable<Sephiroth> GetFamily()
- {
- foreach (Sephiroth element in Children.ToList().Select(e => e.Value).ToList())
- {
- yield return element;
- element.GetFamily();
- }
- }
- public void Destroy()
- {
- Root.Remove(Key);
- }
- public void Relive()
- {
- if (Baby.ContainsKey(Key))
- {
- if (!Root.ContainsKey(Key))
- {
- Root.Add(Key, Baby[Key]);
- }
- }
- }
- public bool IsAncestorOf(Sephiroth element)
- {
- return GetFamily().Contains(element);
- }
- public bool IsDescendantOf(Sephiroth element)
- {
- return element.GetFamily().Contains(element);
- }
- public bool DoesShareHierarchyWith(Sephiroth element)
- {
- return IsAncestorOf(element) || IsDescendantOf(element);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement