解决方法:把鼠标事件删掉
while (true)
{
// 获取一条鼠标消息
m = GetMouseMsg();
if (m.uMsg == WM_RBUTTONUP) {
closegraph(); // 按鼠标右键退出程序
break;
}
switch (m.uMsg)
{
case WM_LBUTTONUP:
startbutton.receiveEvent(m.x, m.y);
answerbutton.receiveEvent(m.x, m.y);
break;
}
if (_kbhit())
{
choice = _getch();
switch (choice)
{
case 'w':
case 'W':
case 72:
moveUP();
break;
case 'a':
case 'A':
case 75:
moveLEFT();
break;
case 's':
case 'S':
case 80:
moveDOWN();
break;
case 'd':
case 'D':
case 77:
moveRIGHT();
break;
default:
break;
}
}
}
具体原理也不清楚,但是把鼠标事件删掉就好了。
while (true)
{
if (_kbhit())
{
choice = _getch();
switch (choice)
{
case 'w':
case 'W':
case 72:
moveUP();
break;
case 'a':
case 'A':
case 75:
moveLEFT();
break;
case 's':
case 'S':
case 80:
moveDOWN();
break;
case 'd':
case 'D':
case 77:
moveRIGHT();
break;
default:
break;
}
}
}