0
我正在尝试构建一个简单的蛇游戏。 功能void Input()
调用_kbhit()
和_getch()
但问题是,我不能实现这些功能的原因conio.h不包括在Linux中的gcc包。是否有替代方法来完成_kbhit()
和_getch()
的任务而不使用conio
头文件?如何在Linux上使用C++实现kbhit()和gethch()
void Input() // handle controls
{
if(_kbhit()) // boolean positive if key is pressed
{
switch(_getch()) // gets ascii val of key pressed
{
case 'a':
dir = LEFT;
break;
case 'd':
dir = RIGHT;
break;
case 'w':
dir = UP;
break;
case 's':
dir = DOWN;
break;
case 'x':
gameOver = true;
break;
}
}
}
再次阅读问题,GetAsyncKeyState()是WinAPI的一部分,他想要的东西为Linux – CrizerPL