Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ncurses.h>
- #include <string.h>
- int main() {
- initscr();
- noecho();
- curs_set(0);
- start_color();
- init_pair(1, COLOR_GREEN, COLOR_YELLOW);
- init_pair(2, COLOR_RED, COLOR_WHITE);
- int cols, rows;
- keypad(stdscr, TRUE);
- getmaxyx(stdscr,rows,cols);
- int i, x=cols/2, y=rows/2,ex=0,ey=0;
- bool run=TRUE;
- while(run){
- erase();
- attron(COLOR_PAIR(1));
- mvprintw(y,x,"o/");
- attroff(COLOR_PAIR(1));
- attron(COLOR_PAIR(2));
- mvprintw(ey,ex,"X");
- attroff(COLOR_PAIR(2));
- refresh();
- timeout(60);
- i=getch();
- switch(i)
- {
- case KEY_LEFT: x--;
- break;
- case KEY_RIGHT: x++;
- break;
- case KEY_DOWN: y++;
- break;
- case KEY_UP: y--;
- break;
- case 27: run=FALSE;
- }
- if(x==cols)
- x=1;
- if(x==0)
- x=cols-1;
- if(y==rows+1)
- y=1;
- if(y==0)
- y=rows;
- if (ex<x) ex++;
- else if (ex>x) ex--;
- if (ey<y)
- ey++;
- else if (ey>y) ey--;
- }
- endwin();
- return 0;
- }
- /*int rows, cols;
- getmaxyx(stdscr,rows,cols);
- char text[]="press any key";
- mvprintw(rows/2,(cols-strlen(text))/2,text);
- getch();*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement