Console animations

前端 未结 11 1697
误落风尘
误落风尘 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:57

    This is the way i solved it, sure it could/can be shorter but, Im just not that smart yet :-)

    void cc() { Console.Clear(); }
    void cr() { Console.ReadKey(); }
    
    byte Sleeptimer = 90;
    void sleepy() { System.Threading.Thread.Sleep(Sleeptimer); }
    
    
    
    
    string[] Loading = { @"-- ", @"\  ", @"|  ", @"/  ", "Loading", " complete!" };
    
    for (byte i = 0; i <= 15; i++)
    {
        cc();
        Console.ForegroundColor = ConsoleColor.Yellow;
        Console.WriteLine(Loading[0] + Loading[4]);
        sleepy();
        cc();
    
        Console.WriteLine(Loading[1] + Loading[4]);
        sleepy();
        cc();
    
        Console.WriteLine(Loading[2] + Loading[4]);
        sleepy();
        cc();
    
        Console.WriteLine(Loading[3] + Loading[4]);
        sleepy();
        cc();
    
        if (i == 15) {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine(Loading[4] + Loading[5]);
    
            cc();
            Console.ForegroundColor = ConsoleColor.Cyan;
            Next();
        }
    }
    /*
        Now i feel even more noob while reading your code.
        I'm a newbie in programing.
    
        Guess this way would work if i just incfement the index of each Loading down below right?
        Learned too much today, forgot how this exactly works, to increment or to change the index i'd lile to acces
    
        Console.WriteLine(Loading[2] + Loading[4]);
        sleepy();
        cc();
    
    */
    

提交回复
热议问题