我目前正在 ncurses 中编写一个游戏,我有一艘由用户控制的飞船和一个缓慢向下移动以杀死你的“自动化”飞船。但是,我使用的是一个包含所有内容的 while 循环,每次我使用 getch() 时,循环都会暂停并等待输入,这意味着敌人只会在用户输入后移动。
c=getch(); //causes a pause until a button is pressed before the next action
if(c==97) //if a is pressed, move position of '*' left
{
dir=-1;
}
if(c==100) //if d is pressed, move position of '*' right
{
dir=1;
}
最佳答案
因为你正在使用 curses,只需调用 nodelay
或 halfdelay
或 timeout
来使 getch
非阻塞,或者如果没有按下任何键,它会在短暂的等待后返回。请参阅 inopts(3ncurses) 手册页。
关于c - 有 getch(); 的替代方法吗?哪个不会暂停程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44052176/