1
0

44_cursorctl.c 519 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include <ncurses.h>
  2. #include <sys/param.h>
  3. int main()
  4. {
  5. initscr();
  6. printw("Press WASD to move the cross, Q to quit\n");
  7. int x = 10;
  8. int y = 10;
  9. refresh();
  10. int ch = 0;
  11. noecho();
  12. while (ch != 'q')
  13. {
  14. ch = getch();
  15. int sy, sx;
  16. getmaxyx(stdscr, sy, sx);
  17. move(y, x);
  18. delch();
  19. if (ch == 'w')
  20. y--;
  21. if (ch == 's')
  22. y++;
  23. if (ch == 'a')
  24. x--;
  25. if (ch == 'd')
  26. x++;
  27. y = MAX(1, MIN(sy - 1, y));
  28. x = MAX(0, MIN(sx - 1, x));
  29. move(y, x);
  30. addch('X');
  31. refresh();
  32. }
  33. endwin();
  34. return 0;
  35. }