Advertisement
Guest User

cursorctl.c

a guest
Jun 22nd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. #include <ncurses.h>
  2. #include <sys/param.h>
  3.  
  4. int main()
  5. {
  6.     initscr();
  7.     printw("Press WASD to move the cross, Q to quit\n");
  8.     int x = 10;
  9.     int y = 10;
  10.     refresh();
  11.     int ch = 0;
  12.     noecho();
  13.     while (ch != 'q')
  14.     {
  15.         ch = getch();
  16.         int sy, sx;
  17.         getmaxyx(stdscr, sy, sx);
  18.         move(y, x);
  19.         delch();
  20.         if (ch == '2')
  21.             y--;
  22.         if (ch == '8')
  23.             y++;
  24.         if (ch == '4')
  25.             x--;
  26.         if (ch == '6')
  27.             x++;
  28.         y = MAX(1, MIN(sy - 1, y));
  29.         x = MAX(0, MIN(sx - 1, x));
  30.         move(y, x);
  31.         addch('O');
  32.         refresh();
  33.     }
  34.     endwin();
  35.     return 0;
  36. }
  37. //dynamically (int double)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement