Advertisement
NickAndNick

SetConsoleCursorPosition

Feb 2nd, 2015
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.66 KB | None | 0 0
  1. // msvc2013
  2. #include <iostream>
  3. #include <Windows.h>
  4. #include <conio.h>
  5. enum DIRECTION {
  6.     A = 65,
  7.     D = 68,
  8.     S = 83,
  9.     W = 87,
  10.     a = 97,
  11.     d = 100,
  12.     s = 115,
  13.     w = 119,
  14.     В = 130,
  15.     Ф = 148,
  16.     Ц = 150,
  17.     Ы = 155,
  18.     в = 162,
  19.     ф = 228,
  20.     ц = 230,
  21.     ы = 235
  22. };
  23. COORD move(COORD, unsigned char);
  24. int main() {
  25.     COORD coord;
  26.     coord.X = 0;
  27.     coord.Y = 0;
  28.     CONSOLE_CURSOR_INFO cursor = { 1, false };
  29.     SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor);
  30.     std::cout << '|';
  31.     unsigned char direction;
  32.     while (true) {
  33.         direction = _getch();
  34.         coord = move(coord, direction);
  35.     }
  36.     return 0;
  37. }
  38. COORD move(COORD coord, unsigned char direction) {
  39.     bool attemp = false;
  40.     switch (direction) {
  41.         case a: case A: case ф: case Ф:
  42.             if (coord.X) {
  43.                 --coord.X;
  44.                 attemp = true;
  45.             }
  46.             break;
  47.         case d: case D: case в: case В:
  48.             if (coord.X < 78) {
  49.                 ++coord.X;
  50.                 attemp = true;
  51.             }
  52.             break;
  53.         case s: case S: case ы: case Ы:
  54.             if (coord.Y < 25) {
  55.                 ++coord.Y;
  56.                 attemp = true;
  57.             }
  58.             break;
  59.         case w: case W: case ц: case Ц:
  60.             if (coord.Y) {
  61.                 --coord.Y;
  62.                 attemp = true;
  63.             }
  64.             break;
  65.         default: break;
  66.     }
  67.     if (attemp) {
  68.         system("cls");
  69.         SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
  70.         std::cout << '|';
  71.     }
  72.     return coord;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement