Esempio n. 1
0
 public object Compress()
 {
     if (_childs[0] is SimpleElement)
     {
         SimpleElement compressed = new SimpleElement();
         if (currentState.IsDown)
         {
             compressed.Turn();
         }
         for (int i = 0; i < 4; i++)
         {
             compressed.SetChild(i, _childs[i].Compress());
         }
         return(compressed);
     }
     else
     {
         Composite compressed = new Composite();
         for (int i = 0; i < 4; i++)
         {
             compressed.SetChild(i, _childs[i].Compress());
         }
         if (currentState.IsDown)
         {
             compressed.Turn();
         }
         return(compressed);
     }
 }
Esempio n. 2
0
        public IElement Clone()
        {
            IElement clone = new SimpleElement();

            if (currentState.IsDown)
            {
                clone.Turn();
            }
            return(clone);
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a pyramid structure recursively, depending on the number of elements in the input string
        /// </summary>
        /// <param name="symbolsCountInInput">The number of elements in the input string</param>
        /// <returns>IElement - new pyramid object</returns>
        private IElement CreateStructure(int symbolsCountInInput)
        {
            IElement firstElement          = new SimpleElement();
            IElement currentElement        = firstElement;
            int      symbolsCountInpyramid = 4;
            int      symbolsLeftInInput    = symbolsCountInInput - symbolsCountInpyramid;

            while (symbolsLeftInInput > 0)
            {
                currentElement = new Composite();
                currentElement.SetChild(0, firstElement);
                currentElement.SetChild(1, firstElement.Clone());
                currentElement.SetChild(2, firstElement.Clone().Turn());
                currentElement.SetChild(3, firstElement.Clone());
                symbolsCountInpyramid *= 4;
                symbolsLeftInInput     = symbolsCountInInput - symbolsCountInpyramid;
                firstElement           = currentElement;
            }
            return(currentElement);
        }