gpt4 book ai didi

c# - Console.Clear() 闪烁

转载 作者:太空宇宙 更新时间:2023-11-03 21:24:04 24 4
gpt4 key购买 nike

while (true)
{
Console.Clear();
for (int row = 0; row < 50; row++)
{
for (int col = 0; col < 50; col++)
{
Console.Write(world[row, col]);
}
Console.WriteLine();
}
Thread.Sleep(500);
}

我正在写一个游戏,我有一个数字,由 10 个字符组成。当单击某些箭头按钮时,我希望它在字符数组中移动。问题是这个游戏一点也不流畅。使用 Console.Clear() 时,控制台会反复闪烁,这很烦人。这个问题有什么解决办法吗? (如果我不想使用 Console.SetCursorPosition(),因为它让制作这个游戏变得更加困难)。

最佳答案

尝试将所有场景汇总到 1 个字符串中而不是一次绘制它,这会将闪烁效果(隐藏)到某个点:

string scene = "";

// iterate your array to construct the scene string
for (int row = 0; row < 50; row++)
{
for (int col = 0; col < 50; col++)
{
scene += world[row, col];
}
scene += '\n'; // new line
}
Console.Clear(); // thanx David
Console.Write(scene);

关于c# - Console.Clear() 闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28490246/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com