我正在使用ncurses库用c++编写Pacman游戏,但我无法使Pacman正常移动。我已经使用
这是一个向上移动的代码片段。我已经根据需要修改了一些条件,写了类似的代码来实现向左、右和下移动。
我使用getch()函数有误吗?或者还需要做些什么操作?
getch()
将其向上、下、左和右移动,但当我按其他键时它只能向右移动而不能在其他方向移动。这是一个向上移动的代码片段。我已经根据需要修改了一些条件,写了类似的代码来实现向左、右和下移动。
int ch = getch();
if (ch == KEY_RIGHT)
{
int i,row,column;
//getting position of cursor by getyx function
for (i=column; i<=last_column; i+=2)
{
//time interval of 1 sec
mvprintw(row,b,"<"); //print < in given (b,row) coordinates
//time interval of 1 sec
mvprintw(row,(b+1),"O"); //print "O" next to "<"
int h = getch(); //to give the option for pressing another key
if (h != KEY_RIGHT) //break current loop if another key is pressed
{
break;
}
}
}
if (condition)
{
//code to move left
}
我使用getch()函数有误吗?或者还需要做些什么操作?