Ejemplo n.º 1
0
        public void DrawEmptyFrameMatrixTest()
        {
            byte[,] actualMatrix =
            {
                { 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 0, 0 }
            };

            string actualString = FieldToString.DrawEmptyFrame(actualMatrix);

            StringBuilder expected = new StringBuilder();

            expected.AppendLine("    0 1 2 3 4 5 6 ");
            expected.AppendLine("   ---------------");
            expected.AppendLine("0 |               |");
            expected.AppendLine("1 |               |");
            expected.AppendLine("2 |               |");
            expected.AppendLine("3 |               |");
            expected.AppendLine("4 |               |");
            expected.AppendLine("5 |               |");
            expected.AppendLine("   ---------------");

            string expectedString = expected.ToString();

            Assert.AreEqual(expectedString, actualString);
        }
Ejemplo n.º 2
0
        public override void RenderGameFieldState(byte[,] fieldClone)
        {
            // the console is cleared only once - at first print of the field
            if (!this.isBackgroundChanged)
            {
                Console.BackgroundColor = ConsoleColor.White;
                Console.Clear();
                this.isBackgroundChanged = true;
            }

            // sets the buffer size to maximum possible, because when printing many lines the cursor gets out of the console and throws an exception
            Console.BufferHeight = short.MaxValue - 1;
            Console.ForegroundColor = ConsoleColor.Black;

            var fieldAsString = FieldToString.DrawEmptyFrame(fieldClone);
            var topCursorPosition = Console.CursorTop;
            Console.WriteLine(fieldAsString);
            var defaultConsoleForegroundColor = Console.ForegroundColor;

            for (int row = 0; row < fieldClone.GetLength(0); row++)
            {
                Console.SetCursorPosition(InitialLeftCursorPosition, topCursorPosition + InitialTopCursorPosition + row);

                for (int col = 0; col < fieldClone.GetLength(1); col++)
                {
                    if (fieldClone[row, col] == 0)
                    {
                        Console.Write("  ");
                        continue;
                    }

                    BaloonColor color = (BaloonColor)fieldClone[row, col];
                    Console.ForegroundColor = (ConsoleColor)Enum.Parse(typeof(ConsoleColor), color.ToString());
                    Console.Write("♥ ");
                }
            }

            Console.SetCursorPosition(0, topCursorPosition + InitialTopCursorPosition + 2 + fieldClone.GetLength(0));
            Console.ForegroundColor = defaultConsoleForegroundColor;
        }