Ejemplo n.º 1
0
        static void Paint(Dude d)
        {
            if (d.LastX >= 0)
            {
                Console.BackgroundColor = ConsoleColor.DarkGreen;
                Console.CursorLeft      = d.LastX;
                Console.CursorTop       = d.LastY;
                Console.Write(" ");
            }

            Console.ForegroundColor = d.Color;
            Console.BackgroundColor = ConsoleColor.Cyan;
            Console.CursorLeft      = d.X;
            Console.CursorTop       = d.Y;
            Console.Write("?");

            d.LastX = d.X;
            d.LastY = d.Y;
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var d = new Dude
            {
                X     = Console.WindowWidth / 2,
                Y     = Console.WindowHeight / 2,
                Color = ConsoleColor.Blue
            };

            var options = new List <string>
            {
                "Quit", "Beep", "Colorize"
            };
            var selectedOption = 0;

            PaintBackground();
            PaintMenu(options, selectedOption);

            var            keepGoing = true;
            ConsoleKeyInfo key;

            do
            {
                Paint(d);
                key = Console.ReadKey(intercept: true);
                switch (key.Key)
                {
                case ConsoleKey.Escape:
                    keepGoing = false;
                    break;

                case ConsoleKey.LeftArrow:
                    d.X--;
                    break;

                case ConsoleKey.RightArrow:
                    d.X++;
                    break;

                case ConsoleKey.UpArrow:
                    d.Y--;
                    break;

                case ConsoleKey.DownArrow:
                    d.Y++;
                    break;

                case ConsoleKey.Tab:
                    selectedOption++;
                    if (selectedOption >= options.Count)
                    {
                        selectedOption = 0;
                    }
                    PaintMenu(options, selectedOption);
                    break;

                case ConsoleKey.Enter:
                    if (options[selectedOption] == "Quit")
                    {
                        keepGoing = false;
                    }
                    else if (options[selectedOption] == "Beep")
                    {
                        Console.Beep();
                    }
                    else if (options[selectedOption] == "Colorize")
                    {
                        d.Color = (ConsoleColor)random.Next(16);
                    }
                    break;
                }
            } while (keepGoing);
        }