private void StartGame()
{
Dsnake = new Ds(Putfood);
this.Invoke(Dsnake, null);
while (true)
{
Thread.Sleep(speed);
if (sb.HasEatfood(temppoint))
{
Dsnake = new Ds(Killfood);
this.Invoke(Dsnake, null);
Dsnake = new Ds(Putfood);
this.Invoke(Dsnake, null);
}
Dsnake = new Ds(Movesnakes);
this.Invoke(Dsnake, null);
if (isGameover())
{
MessageBox.Show("GAME OVER");
try
{
thread.Abort();
}
catch
{
}
}
}
//if(sb.HasEatfood(temppoint))
//{
//
Dsnake = new Ds(Killfood);
//
this.Invoke(Dsnake, null);
//
Dsnake = new Ds(Putfood);
//
this.Invoke(Dsnake, null);
//}
//Dsnake = new Ds(Movesnakes);
//this.Invoke(Dsnake, null);
}
form1中的StartGame方法,如上代码,将注释代码放入while中即可
不过除此以外,程序还有不少bug,但应该都是些小问题