ncurses 无法在结构的 x y 位置上显示元素

ncurses can't display element on x y position from structure

我正在尝试显示带有 ncurses 的机器人。 当使用 printf 打印 x 和 y 时,一切正常,但使用 mvwprintw(window, x, y, "a"); 时没有任何显示。 问题是什么?

文件:查看。

#include <ncurses.h>
#include "config.c"
#include "arena.c"

void create_window(){
    robot robots[NUMBER_ROBOTS];

    create_robots(robots);
    initscr();
    raw();
    noecho();

    WINDOW * window = newwin(TERM_HEIGHT, TERM_WIDTH, 0, 0);

    refresh();

    box(window, 0,0); 

    for (size_t i = 0; i < NUMBER_ROBOTS; i++)
    {   
        //to_string(robots[i]);
        int x = get_posx(robots[i]);
        int y = get_posy(robots[i]);

        printf("X%d Y%d\n", x, y);

        wrefresh(window);
        mvwprintw(window, x, y, "a");

    }
    wrefresh(window);
    getch(); 
    endwin();
}

void launch(int argc, char const *argv[])
{   

    create_window(); 

}

文件robot.h


typedef struct robot{
  int state;
  char id[1];
  double posX,posY;
  double posXo,posYo;
  int speed;
  int life;
  missile missiles[2];  
} robot ;


文件arena.c


int get_posx(robot r){
    return (r.posX*TERM_WIDTH)/WIDTH;
}

int get_posy(robot r){
    return (r.posY*TERM_HEIGHT)/HEIGHT;
}

执行画面:enter image description here 有 "a" 显示。

有几种可能性:

  • mvwprintw 的调用交换了 x/y 坐标(因此它将采用相当大的 x 值并将其作为行号,丢失超出范围时写入的任何文本)
  • 屏幕截图没有显示框的底部(也许 TERM_HEIGHT 不正确,加剧了坐标问题)
  • printf 妨碍了对光标实际位置的诅咒
  • getch 应该是 wgetch(window),以防万一(我没看到)stdscr.
  • 有待更新