好的,我的最后一个问题并不是很清楚,所以我删除了它并提出了这个问题。我正在制作游戏“蛇”。我想要的是,在我选择了一个难度之后,表单上的按键需要起作用(你选择了一个难度,蛇被画出来并开始移动,为了让它移动到你喜欢的方向,你按下箭头键)在我添加困难之前,它工作得很好。现在我选择了难度并想玩游戏后,蛇不动,我的按键在程序中没有反应。
所以我的问题=选择难度后keyDown不起作用。
private void btnNormal_Click(object sender, EventArgs e)
{
timer1.Interval = 250;
btnNormal.Visible = false;
btnEasy.Visible = false;
btnHard.Visible = false;
diffLabel.Visible = false;
timer1.Enabled = true;
down = false;
up = false;
right = true;
left = false;
}
private void btnHard_Click(object sender, EventArgs e)
{
timer1.Interval = 10;
btnNormal.Visible = false;
btnEasy.Visible = false;
btnHard.Visible = false;
diffLabel.Visible = false;
timer1.Enabled = true;
down = false;
up = false;
right = true;
left = false;
}
private void btnEasy_Click(object sender, EventArgs e)
{
timer1.Interval = 500;
btnNormal.Visible = false;
btnEasy.Visible = false;
btnHard.Visible = false;
diffLabel.Visible = false;
timer1.Enabled = true;
down = false;
up = false;
right = true;
left = false;
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Down && up == false)
{
down = true;
right = false;
up = false;
left = false;
}
if (e.KeyData == Keys.Up && down == false)
{
down = false;
right = false;
up = true;
left = false;
}
if (e.KeyData == Keys.Right && left == false)
{
down = false;
right = true;
up = false;
left = false;
}
if (e.KeyData == Keys.Left && right == false)
{
down = false;
right = false;
up = false;
left = true;
}
}