【发布时间】:2017-10-18 12:41:45
【问题描述】:
我正在编写一个当前在 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;
}
【问题讨论】:
-
这个函数的传统名称是 kbhit()。键盘敲击的非黑屏检测,通常用于视频游戏目的。
-
@d9ngle:这不是关于如何使用curses不进行非阻塞输入。有了curses,就容易多了。