Ncurses ライブラリを使用して C++ で Pacman を作成しています。私のコードでパックマンを動かすことはできますが、キーを押していなくてもパックマンが動き続け、別の方向キーを押すと方向が変わるように動かしたいと思います。現在、キーを押しても pacman は 1 ステップしか進みません。また、パックマンがその方向に移動する前に、キーを 2 ~ 3 回押す必要があります。
if (ch==KEY_LEFT)
{
int b,row,column;
getyx(stdscr,row,column);
int h;
do // do-whileloop to move the pacman left until it hits the wall
{
column-=1;
mvprintw(row,column,">"); //print the ">" symbol
refresh();
waitf(0.1); //this pauses the game for 0.1sec
attron(COLOR_PAIR(1));
mvprintw(row,column,">");
attroff(COLOR_PAIR(1));
refresh();
waitf(0.1);
mvprintw(row,(b),"O"); //showing the open mouth of pacman
refresh();
waitf(0.1);
attron(COLOR_PAIR(1));a
mvprintw(row,column,"O");
attroff(COLOR_PAIR(1));
h = getch();
}
while(h == KEY_LEFT);
}
right = getch();
if条件で右に移動するループ
up = getch();
if条件で上に移動するループ
down = getch();
if条件で下に移動するためのおっと。