我想要做的是启动一个函数,然后将一个布尔值更改为false,等待一秒钟,再将其设置为true。然而,我希望在函数不必等待的情况下完成它,我应该怎么做?
我只能使用Visual C# 2010 Express。
下面是有问题的代码。我正在尝试接收用户输入(比如向右箭头),并相应地移动,但在角色移动时不允许进一步的输入。
我只能使用Visual C# 2010 Express。
下面是有问题的代码。我正在尝试接收用户输入(比如向右箭头),并相应地移动,但在角色移动时不允许进一步的输入。
x = Test.Location.X;
y = Test.Location.Y;
if (direction == "right")
{
for (int i = 0; i < 32; i++)
{
x++;
Test.Location = new Point(x, y);
Thread.Sleep(31);
}
}
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
int xmax = Screen.PrimaryScreen.Bounds.Width - 32;
int ymax = Screen.PrimaryScreen.Bounds.Height - 32;
if (e.KeyCode == Keys.Right && x < xmax) direction = "right";
else if (e.KeyCode == Keys.Left && x > 0) direction = "left";
else if (e.KeyCode == Keys.Up && y > 0) direction = "up";
else if (e.KeyCode == Keys.Down && y < ymax) direction = "down";
if (moveAllowed)
{
moveAllowed = false;
Movement();
}
moveAllowed = true;
}