Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include <ncurses.h>
  2. #include <string.h>
  3. int main() {
  4.  
  5. initscr();
  6. noecho();
  7. curs_set(0);
  8. start_color();
  9. init_pair(1, COLOR_GREEN, COLOR_YELLOW);
  10. init_pair(2, COLOR_RED, COLOR_WHITE);
  11. int cols, rows;
  12. keypad(stdscr, TRUE);
  13. getmaxyx(stdscr,rows,cols);
  14. int i, x=cols/2, y=rows/2,ex=0,ey=0;
  15. bool run=TRUE;
  16. while(run){
  17. erase();
  18. attron(COLOR_PAIR(1));
  19. mvprintw(y,x,"o/");
  20. attroff(COLOR_PAIR(1));
  21.  
  22. attron(COLOR_PAIR(2));
  23. mvprintw(ey,ex,"X");
  24. attroff(COLOR_PAIR(2));
  25. refresh();
  26. timeout(60);
  27. i=getch();
  28.  
  29. switch(i)
  30. {
  31. case KEY_LEFT: x--;
  32. break;
  33. case KEY_RIGHT: x++;
  34. break;
  35. case KEY_DOWN: y++;
  36. break;
  37. case KEY_UP: y--;
  38. break;
  39. case 27: run=FALSE;
  40.  
  41. }
  42. if(x==cols)
  43. x=1;
  44. if(x==0)
  45. x=cols-1;
  46. if(y==rows+1)
  47.  
  48. y=1;
  49. if(y==0)
  50. y=rows;
  51. if (ex<x) ex++;
  52. else if (ex>x) ex--;
  53. if (ey<y)
  54. ey++;
  55. else if (ey>y) ey--;
  56. }
  57. endwin();
  58. return 0;
  59. }
  60.  
  61.  
  62. /*int rows, cols;
  63. getmaxyx(stdscr,rows,cols);
  64. char text[]="press any key";
  65. mvprintw(rows/2,(cols-strlen(text))/2,text);
  66. getch();*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement