示例#1
0
        private void switchWithplaces(int[] array, string message, int leftIndex, int rightIndex, State state)
        {
            Console.Clear();
            Console.ResetColor();
            Console.ForegroundColor = textColor;

            Console.WriteLine(message);
            Console.WriteLine();

            int[] switchedArray = (int[])array.Clone();
            int   tmp           = switchedArray[leftIndex];

            switchedArray[leftIndex]  = switchedArray[rightIndex];
            switchedArray[rightIndex] = tmp;

            DisplayMatrix displayMatrix = generateDispalyMatrix(switchedArray, message, leftIndex, rightIndex, state);

            for (int i = 0; i < displayMatrix.getHeight(); i++)
            {
                for (int j = 0; j < displayMatrix.getWidth(); j++)
                {
                    Console.ForegroundColor = displayMatrix.getArrayTuple()[i, j].Item1;
                    Console.Write(displayMatrix.getArrayTuple()[i, j].Item2);
                }
                Console.WriteLine();
            }
        }
示例#2
0
        protected DisplayMatrix generateDispalyMatrixSameLine(int[] array, string message, int leftIndex, int rightIndex, State state)
        {
            DisplayMatrix dispalyMatrix = new DisplayMatrix((array.Select(x => x.ToString().Length + 1).Sum() / Console.WindowWidth + 1) * 2, Console.WindowWidth);

            int widthIndex  = 0;
            int heightIndex = 1;

            for (int arrayIdx = 0; arrayIdx < array.Length; arrayIdx++)
            {
                if ((widthIndex + array[arrayIdx].ToString().Length + 2) > dispalyMatrix.getWidth())
                {
                    widthIndex   = 0;
                    heightIndex += 2;
                }

                foreach (char character in array[arrayIdx].ToString().ToCharArray())
                {
                    if (arrayIdx == leftIndex || arrayIdx == rightIndex)
                    {
                        dispalyMatrix.getArrayTuple()[heightIndex, widthIndex++] = Tuple.Create((ConsoleColor)state, character);
                    }
                    else
                    {
                        dispalyMatrix.getArrayTuple()[heightIndex, widthIndex++] = Tuple.Create(defaultCharColor, character);
                    }
                }
                widthIndex++;
            }

            return(dispalyMatrix);
        }
示例#3
0
        private void liftUp(int[] array, string message, int leftIndex, int rightIndex, State state)
        {
            Console.Clear();
            Console.ResetColor();
            Console.ForegroundColor = textColor;

            Console.WriteLine(message);
            Console.WriteLine();

            DisplayMatrix displayMatrix = generateDispalyMatrix(array, message, leftIndex, rightIndex, state);

            for (int i = 0; i < displayMatrix.getHeight(); i++)
            {
                for (int j = 0; j < displayMatrix.getWidth(); j++)
                {
                    Console.ForegroundColor = displayMatrix.getArrayTuple()[i, j].Item1;
                    Console.Write(displayMatrix.getArrayTuple()[i, j].Item2);
                }
                Console.WriteLine();
            }
        }
示例#4
0
        public override void animate(int[] array, string message, int leftIndex, int rightIndex, State state)
        {
            Console.Clear();
            Console.ResetColor();
            Console.ForegroundColor = textColor;

            string finalMessage = !string.IsNullOrEmpty(message) ? message : convertStateToMessage(state, leftIndex, rightIndex);

            Console.WriteLine(finalMessage);
            Console.WriteLine();

            DisplayMatrix displayMatrix = generateDispalyMatrixSameLine(array, message, leftIndex, rightIndex, state);

            for (int i = 0; i < displayMatrix.getHeight(); i++)
            {
                for (int j = 0; j < displayMatrix.getWidth(); j++)
                {
                    Console.ForegroundColor = displayMatrix.getArrayTuple()[i, j].Item1;
                    Console.Write(displayMatrix.getArrayTuple()[i, j].Item2);
                }
                Console.WriteLine();
            }
        }