使用 Ncurses 向我想要的方向移动一个点
Moving a point in direction i want using Ncurses
我想在 linux 终端中向我想要的方向移动一个点,但它没有发生 a/c 我希望我无法找到我失踪的地方。
这是我的代码`
#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;
}
第一期(不知道ncurses api):找出什么getch()
returns。这通常是一个 ascii 字符,值 1、2、3 和 5 不是键盘传递的 ascii 值。您可能需要引用的字符:'1'、'2'、'3' 和 '5' 尽管 ncurses' manual 显示了如何使用 KEY_LEFT
,... 来读取箭头键
我想在 linux 终端中向我想要的方向移动一个点,但它没有发生 a/c 我希望我无法找到我失踪的地方。 这是我的代码`
#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;
}
第一期(不知道ncurses api):找出什么getch()
returns。这通常是一个 ascii 字符,值 1、2、3 和 5 不是键盘传递的 ascii 值。您可能需要引用的字符:'1'、'2'、'3' 和 '5' 尽管 ncurses' manual 显示了如何使用 KEY_LEFT
,... 来读取箭头键