Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何在C++;在linux上_C++ - Fatal编程技术网

C++ 如何在C++;在linux上

C++ 如何在C++;在linux上,c++,C++,我正在尝试建立一个原始的蛇游戏。 函数void Input()调用\u kbhit()和\u getch() 但问题是我无法实现这些函数,因为linux中的gcc包中不包含conio.h。是否有其他方法可以在不使用conio头文件的情况下完成\u kbhit()和\u getch()任务 void Input() // handle controls { if(_kbhit()) // boolean positive if key is pressed { switch(_getch())

我正在尝试建立一个原始的蛇游戏。 函数
void Input()
调用
\u kbhit()
\u getch()
但问题是我无法实现这些函数,因为linux中的gcc包中不包含conio.h。是否有其他方法可以在不使用
conio
头文件的情况下完成
\u kbhit()
\u getch()
任务

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;
    }
}   
}

这些函数是“非法”的,在标准C++中不再使用。 图书馆会有帮助的

顺便说一下,ncurses定义了TRUE和FALSE。一个正确配置的NCURESS将使用NCRES'BoL的相同数据类型作为用于配置NCURESE的C++编译器。 下面是一个示例,说明如何使用ncurses,如conio示例:

#include <ncurses.h>
int main()
{
initscr();
cbreak();
noecho();
scrollok(stdscr, TRUE);
nodelay(stdscr, TRUE);
while (true) {
    if (getch() == 'g') {
        printw("You pressed G\n");
    }
    napms(500);
    printw("Running\n");
}
}
#包括
int main()
{
initscr();
cbreak();
noecho();
scrollok(stdscr,TRUE);
节点延迟(stdscr,真);
while(true){
如果(getch()='g'){
printw(“您按下了G\n”);
}
国家行动方案(500);
printw(“正在运行的\n”);
}
}

请再次阅读问题,GetAsyncKeyState()是WinAPI的一部分,他希望为linux提供一些功能