当前位置: 动力学知识库 > 问答 > 编程问答 >

c - Ncurses scrolling lines

问题描述:

I'm doing a simple Frogger game for my subject, but my code have a problem that i dont know how to fix it. I've been using mvprintw in a function to move a "object" across the map in the same direction ever, but when it finished the first full map and begins again it scrolling up one line, how can i avoid that scrolling?

Heres the object function:

void rand_obj1 (int y)

{

init_pair (3, COLOR_RED , COLOR_CYAN);

attron(COLOR_PAIR(3));

mvprintw (20,y, " _ _ _ _");

mvprintw (21,y, "() _ )");

mvprintw (22,y, "()_ _ _ _)");

mvprintw (10,y, " _ _ _ _");

mvprintw (11,y, "() _ )");

mvprintw (12,y, "()_ _ _ _)");

usleep(delay1);

}

And the loop that a used on my main fuction to show the map e reset the coordinate to object walk throguh all over the begin again:

while (1)

{

if (y >= max_x) y=0;

//map

lago(4,0,max_x,max_y*(0.48),1);

//create obj

rand_obj1 (y);

refresh();

y++;

}

网友答案:

There's nothing in the given example which would do what is described.

Your program (in the parts not shown) is probably writing messages to the terminal with printf, and these messages are not seen (or taken into account) by the curses library.

For instance, it could be in this call:

lago(4,0,max_x,max_y*(0.48),1);

From comments, lago is not the cause. Running the sample program shows that it uses an extra line (due to wraparound), giving a total of 23 lines. Normally this is not a problem, but suppose that your terminal is 23 lines (which could happen) and if you had also set the environment variable LINES to 24 (also possible), then you'd see wrapping as shown in this picture:

The mismatch is possible for instance if you had configured the terminal to start with 23 lines (or are running it via an IDE which did this for you) and noticed some problem and then set the environment variable to fix this. The environment variable overrides curses' notion of the screensize (though that can be altered using use_env).

分享给朋友:
您可能感兴趣的文章:
随机阅读: