Esempio n. 1
0
 protected void SetLevels(TowerItem item, int level)
 {
     item._level = level;
     foreach (var i in item._children)
     {
         SetLevels(i, level + 1);
     }
 }
Esempio n. 2
0
        public new int Result()
        {
            int       result = 0;
            TowerItem bottom = null;

            foreach (var item in _items)
            {
                item.SetHierarchy(_items);
            }
            foreach (var item in _items)
            {
                if (item._parent == null && item._children.Count != 0)
                {
                    bottom = item;
                }
            }
            SetLevels(bottom, 0);
            SetSumOfChildrenOfAll();
            if (bottom != null)
            {
                while (true)
                {
                    var index = bottom.IndexOfBadChildren();
                    if (index != -1)
                    {
                        bottom = bottom._children[index];
                    }
                    else
                    {
                        if (bottom._goodValueOfChild * bottom._children.Count != bottom._sumOfChildren)
                        {
                            if (bottom._parent != null)
                            {
                                result = bottom._parent._goodValueOfChild - bottom._goodValueOfChild * bottom._children.Count;
                                break;
                            }
                        }
                    }
                }
            }

            return(result);
        }
 public void SetParent(TowerItem parent)
 {
     _parent = parent;
 }