这是我的第一个问题。我正在为我的c#类构建一个简单的程序来模拟老虎机,并且我正在模拟列?使用这段代码实现旋转效果
static void EfeitoJackpot()
{
string[] simbolos = new string[10] { "!", "#", "$", "%", "&", "=", "@", "~", "»", "«" };
Console.SetCursorPosition(25, 1);
for (int i = 0; ; i++)
{
Console.Write(simbolos[i % 10] + "\b");
System.Threading.Thread.Sleep(80); // velocidade
}
}现在,我的问题是我想要同时显示这个发生了3倍的情况。我一直在阅读关于MultiThreading和并行循环的文章,但经过这么多努力,我仍然被卡住了。
总而言之,我希望这一切都能实现
** [ spinning ] [ spinning ] [ spinning ] **这就是正在发生的事情
** [ spinning ] ..(method finishes executing)... [spinning] and so forth发布于 2019-12-02 04:36:40
既然您说您正在构建一个“简单的程序”,那么您就不需要使用多线程,因为它会使事情变得过于复杂。您可以只使用循环结构。如下所示:
const int MAX = 10;
string[] simbolos = new string[MAX] { "!", "#", "$", "%", "&", "=", "@", "~", "»", "«" };
// Start with some random positions for each column.
Random r = new Random();
int column1Index = r.Next(MAX);
int column2Index = r.Next(MAX);
int column3Index = r.Next(MAX);
// Track overall status, and status of each column.
bool keepSpinning = true;
bool spin1 = true, spin2 = true, spin3 = true;
while (keepSpinning)
{
Console.WriteLine($"{simbolos[column1Index]} {simbolos[column2Index]} {simbolos[column3Index]}");
if (spin1)
{
column1Index = column1Index < MAX - 1 ? column1Index + 1 : 0;
spin1 = SomethingToDetermineIfColumnShouldKeepSpinning(1);
}
if (spin2)
{
column2Index = column2Index < MAX - 1 ? column2Index + 1 : 0;
spin2 = SomethingToDetermineIfColumnShouldKeepSpinning(2);
}
if (spin3)
{
column3Index = column3Index < MAX - 1 ? column3Index + 1 : 0;
spin3 = SomethingToDetermineIfColumnShouldKeepSpinning(3);
}
}https://stackoverflow.com/questions/59129338
复制相似问题