简体   繁体   English

使用Ncurses向我想要的方向移动点

[英]Moving a point in direction i want using Ncurses

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. 我想在linux终端中向我想要的方向移动一点,但是这并没有按照我的愿望进行,所以我无法找出丢失的地方。 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. 第一个问题(实际上不了解ncurses api):找出getch()返回的结果。 This is usually an ascii character and values 1, 2, 3 and 5 are not ascii values that are passed by keyboard. 这通常是一个ascii字符,并且值1、2、3和5不是键盘传递的ascii值。 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 您可能想要用引号引起来的字符:“ 1”,“ 2”,“ 3”和“ 5”,尽管《 ncurses》手册显示了如何使用KEY_LEFT ,...来读取箭头键

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM