Beispiel #1
0
        private static void DrawInstructions()
        {
            var resetConsoleWindowAspect = new ResetConsoleWindowAspect();

            resetConsoleWindowAspect.OnEntry();

            try
            {
                Console.CursorTop = 3;
                ConsoleEx.WriteLine(3, "Instructions: ", ConsoleColor.White);
                ConsoleEx.WriteLine(4, "Enter commands to move a toy robot around a 5x5 unit table.", ConsoleColor.DarkGray);
                ConsoleEx.Write(4, "Enter '", ConsoleColor.DarkGray);
                ConsoleEx.Write("Report", ConsoleColor.Gray);
                ConsoleEx.WriteLine("' to exit.", ConsoleColor.DarkGray);
                Console.WriteLine();
                ConsoleEx.WriteLine(3, "Valid Commands", ConsoleColor.White);
                ConsoleEx.WriteLine(3, " - Place", ConsoleColor.DarkYellow);
                ConsoleEx.WriteLine(3, " - Move", ConsoleColor.DarkYellow);
                ConsoleEx.WriteLine(3, " - Left", ConsoleColor.DarkYellow);
                ConsoleEx.WriteLine(3, " - Right", ConsoleColor.DarkYellow);
                ConsoleEx.WriteLine(3, " - Block", ConsoleColor.DarkYellow);
                ConsoleEx.WriteLine(3, " - Report", ConsoleColor.DarkYellow);
            }
            finally
            {
                resetConsoleWindowAspect.OnExit();
            }
        }
Beispiel #2
0
        public static void ClearLine()
        {
            var resetConsoleWindowAspect = new ResetConsoleWindowAspect();

            resetConsoleWindowAspect.OnEntry();

            try
            {
                Console.Write(new string(' ', Console.WindowWidth));
            }
            finally
            {
                resetConsoleWindowAspect.OnExit();
            }
        }
Beispiel #3
0
        public static void ClearLine(int lineNumber)
        {
            var resetConsoleWindowAspect = new ResetConsoleWindowAspect();

            resetConsoleWindowAspect.OnEntry();

            try
            {
                Console.SetCursorPosition(0, lineNumber);
                Console.Write(new string(' ', Console.WindowWidth));
            }
            finally
            {
                resetConsoleWindowAspect.OnExit();
            }
        }
Beispiel #4
0
        public static void ClearLine(int lineNumber, int start, int length)
        {
            var resetConsoleWindowAspect = new ResetConsoleWindowAspect();

            resetConsoleWindowAspect.OnEntry();

            try
            {
                Console.SetCursorPosition(start, lineNumber);
                if ((start + length) > Console.WindowWidth)
                {
                    length = Console.WindowWidth - start - 1;
                }
                Console.Write(new string(' ', length));
            }
            finally
            {
                resetConsoleWindowAspect.OnExit();
            }
        }
Beispiel #5
0
        /// <summary>Draws a box to the console.</summary>
        /// <param name="x">The x-coordinate of the top left corner.</param>
        /// <param name="y">The y-coordinate of the top left corner.</param>
        /// <param name="width">The <paramref name="width" /> of the box to draw..</param>
        /// <param name="height">The <paramref name="height" /> of the box to draw..</param>
        /// <param name="clearContents">if set to <c>true</c> the inside of the box is cleared.; otherwise only the box is rendered.</param>
        /// <param name="foreColor">The foreground colour to write.</param>
        /// <param name="backgroundColor">The background colour to write.</param>
        public static void DrawBox(int x, int y, int width, int height, bool clearContents = false, ConsoleColor foreColor = ConsoleColor.White, ConsoleColor backgroundColor = ConsoleColor.Black)
        {
            var resetConsoleWindowAspect = new ResetConsoleWindowAspect();

            resetConsoleWindowAspect.OnEntry();

            try
            {
                width  = Math.Min(width, Console.WindowWidth);
                height = Math.Min(height, Console.WindowHeight);

                Console.CursorLeft = x;
                Console.CursorTop  = y;

                ConsoleEx.Write("┌", foreColor, backgroundColor);
                ConsoleEx.Write(new string('─', width - 2), foreColor, backgroundColor);
                ConsoleEx.Write("┐", foreColor, backgroundColor);
                Console.CursorTop++;

                if (clearContents)
                {
                    for (int rowIndex = 1; rowIndex < height; rowIndex++)
                    {
                        Console.CursorLeft = x;
                        ConsoleEx.Write($"│{new string(' ', width - 2)}│", foreColor, backgroundColor);
                        Console.CursorTop = y + rowIndex;
                    }
                }

                Console.CursorLeft = x;
                ConsoleEx.Write("└", foreColor, backgroundColor);
                ConsoleEx.Write(new string('─', width - 2), foreColor, backgroundColor);
                ConsoleEx.Write("┘", foreColor, backgroundColor);
            }
            finally
            {
                resetConsoleWindowAspect.OnExit();
            }
        }