Console animations

前端 未结 11 1685
误落风尘
误落风尘 2020-12-04 10:15

I just want to know how to create simple animations like blinking, moving stuffs on C# console applications. Is there any special method for this?

11条回答
  •  鱼传尺愫
    2020-12-04 10:44

    Just saw this and a few other threads about it and love this kind of stuff! I took Tuukka's nice piece of code and improved it a bit so the class can easily be set to just about any spin sequence. I'll probably add some accessors and an overloaded constructor to polish it off and put it in the ol' toolbox. Fun stuff!

    class ConsoleSpinner
    {
        int counter;
        string[] sequence;
    
        public ConsoleSpinner()
        {
            counter = 0;
            sequence = new string[] { "/", "-", "\\", "|" };
            sequence = new string[] { ".", "o", "0", "o"};
            sequence = new string[] { "+", "x" };
            sequence = new string[] { "V", "<", "^", ">" };
            sequence = new string[] { ".   ", "..  ", "... ", "...." };
        }
    
        public void Turn()
        {
            counter++;
    
            if (counter >= sequence.Length)
                counter = 0;
    
            Console.Write(sequence[counter]);
            Console.SetCursorPosition(Console.CursorLeft - sequence[counter].Length, Console.CursorTop);
        }
    }
    

提交回复
热议问题