I want to move a point in the direction I want in linux terminal but it is not happening a/c to my wish I am not able to find out where I am missing. Here is my code`
#include<iostream>
#include<ncurses.h>
using namespace std;
int main()
{ int x=10;
int y=10;
int z=3;
initscr();
for(;;)
{ WINDOW*win=newwin(75, 75, 3, 2);
wrefresh(win);
wmove(win,y,x);
raw();
noecho();
wprintw(win,"*");
wrefresh(win);
usleep(600000);
wmove(win,y,x);
wprintw(win," "); //prints space at the coordinates of point where it has earlier print *
wrefresh(win);
nodelay(stdscr,TRUE);
z=getch();
switch(z)
{
case 5:y+=1;
break;
case 2:y-=1;
break;
case 3:x+=1;
break;
case 1:x-=1;
break;
}
}
endwin();
return 0;
}
First issue (without actually knowing the ncurses api): find out what getch()
returns. This is usually an ascii character and values 1, 2, 3 and 5 are not ascii values that are passed by keyboard. You probably want characters which are quoted: '1', '2', '3' and '5' although ncurses' manual shows how to use KEY_LEFT
,... to read in arrow-keys
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.