如何在c#中制作三个加载点 [英] How to make three loading dots in c#
问题描述
您好,
I在c#中我的基于文本的游戏有问题。当用户等待按"输入"时,我希望有一个带有三个加载点的循环。在下面的代码中,我可以让三个点一次出现一个,但是为了让它们消失并且重复同样的事情直到用户按下"输入"而奋斗
。有没有人有这方面的解决方案?
Console.Write("按'Enter'继续');
string dots =" ..." ;;
for(int i = 0; i< dots.Length; i ++)
{
Console.Write(punkter [i]);
System.Threading。
Thread.Sleep(50);
}
Console.ReadLine();
问候Svetarn。
你可以通过写作使点消失一个回车符("\ r")返回到行的开头,写三个空格来擦除现有的点,然后再写一个回车符。或者你可以使用Console.SetCursorPosition
获得相同的效果,而不是写回车符。
等待用户输入比听起来更困难。您可能需要使用计时器来写入点,而主线程则等待输入。
https://docs.microsoft.com/en-us/dotnet/api/system.threading.timer?view=netframework-4.7。 2
Hi,
I have a problem with my textbased game in c#. While the user is waiting to press 'enter', I want to have a loop with three loading dots. In the code below I'm able to make the three dots appear one at a time, but struggle to make them disappear and repeat the same thing until the user presses 'enter'. Does anyone have a solution for this?
Console.Write("Press 'Enter' to continue"); string dots = "..."; for (int i = 0; i<dots.Length; i++) { Console.Write(punkter[i]); System.Threading. Thread.Sleep(50); } Console.ReadLine();
Greetings Svetsarn.
You can make the dots disappear by writing a carriage-return ("\r") to go back to the start of the line, writing three spaces to erase the existing dots, then writing another carriage-return. Or you can get the same effect using Console.SetCursorPosition instead of writing carriage-return.
Waiting for the user input is more difficult than it sounds. You will probably need to use a timer to write the dots, while the main thread waits for input.
https://docs.microsoft.com/en-us/dotnet/api/system.threading.timer?view=netframework-4.7.2
这篇关于如何在c#中制作三个加载点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!