【发布时间】:2015-07-07 08:11:33
【问题描述】:
我正在制作一个游戏,但使用 Console.Write() 重绘游戏场不是很好。有没有什么方法可以更快地重写整个场而不让它看起来“滞后”?运动场中的几乎所有东西都在移动,但只有在 0 以外的元素处才有对象。(您可以在此处查看完整代码 http://pastebin.com/TkPd37xD,如果我的描述不够,请查看我在说什么)
for (int Y = 0; Y < playfield.GetLength(0); Y++)
{
for (int X = 0; X < playfield.GetLength(1); X++)
{
//destroying the row when it reaches the top
if (playfield[0, X] != 0)
{
for (int i = 0; i < playfield.GetLength(1); i++)
{
playfield[0, X] = 0;
Console.SetCursorPosition(X, 0);
Console.Write(" ");
}
}
if (playfield[Y, X] == 3)
{
playfield[Y - 1, X] = 3;
playfield[Y, X] = 0;
}
else if (playfield[Y, X] == 1)
{
Console.SetCursorPosition(X, Y - 1);
Console.Write("=");
playfield[Y - 1, X] = 1;
Console.SetCursorPosition(X, Y);
Console.Write(" ");
playfield[Y, X] = 0;
}
else if (playfield[Y, X] == 0)
{
Console.SetCursorPosition(X, Y);
Console.Write(" ");
}
}
}
【问题讨论】:
-
只是不要重绘整个屏幕,只重绘改变的部分
-
我以为这就是我正在做的事情,但显然我不是,刚才我注意到我的最后一个“Else if”是不必要的,因为我在 else if 做同样的事情当 == 1 时,我删除了最后一个 Else if,现在看起来好多了! :)
-
您尝试过使用字符串缓冲区吗?
-
最初的 windows 控制台可能不是最快的。
标签: c#