我正在编写一个非常简单的游戏,以在UNIX OS上学习C语言。由窗口中的玩家控制的“ C”字符(小鸡)后面是一两个前任。应该如何擦除它们?
#include <time.h>
#include <ncurses.h>
WINDOW *create_newwin(int h, int l, int y, int x)
{ WINDOW *local_win;
local_win = newwin(h, l, y, x);
box(local_win, 0 , 0);
wrefresh(local_win);
return local_win;
}
int main(int argc, char **argv)
{
WINDOW *win;
int x, y, h, l; // window
int px, py; // chicken
int v1x; // car 1
int ch, top=0;
initscr();
cbreak();
keypad(stdscr, TRUE);
nodelay(stdscr, TRUE);
curs_set(0);
h = 30;
l = 60 ;
y = (LINES - h) / 2;
x = (COLS - l) / 2;
py = 1;
px = 30;
v1x = 1;
while ((ch = getch()) != 'q' && (py != 10 || px != v1x)){
if (clock() > top + 100 ){
top = clock();
win = create_newwin(h, l, y, x); // moving car
mvwhline(win, 10, 1, '.', 58);
mvwaddch(win, 10, v1x, 'V');
v1x++;
if (v1x > 58)
v1x = 1;
}
switch(ch){ // moving chicken
case KEY_LEFT:
px--;
break;
case KEY_RIGHT:
px++;
break;
case KEY_UP:
py--;
break;
case KEY_DOWN:
py++;
break;
}
mvwaddch(win, py, px,'C');
wrefresh(win);
}
endwin();
return 0;
}