我正在尝试显示一个具有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
正在进行更新。