0

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;
}
B001ᛦ
  • 2,036
  • 6
  • 23
  • 31

1 Answers1

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

stefaanv
  • 14,072
  • 2
  • 31
  • 53