Control.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "Control.h"
  2. char key;// äëÿ ââîäà êîäà ñèìâîëà ñ êëàâèàòóðû
  3. char keep_direct;// äëÿ ñîõðàíåíèÿ ñèìâîëà íàïðàâëåíèÿ äâèæåíèÿ.
  4. //int _getch(void);// ïîëó÷àåò ñèìâîë èç êîíñîëè áåç îòîáðàæåíèÿ
  5. int main()
  6. {
  7. std::cout << "Press any key" << std::endl;
  8. do
  9. {
  10. key = _getch();
  11. if (key == 0 || key == -32)
  12. {
  13. keep_direct = _getch();
  14. switch (keep_direct)
  15. {
  16. case up: {std::cout << "up" << std::endl; }
  17. break;
  18. case down: {std::cout << "down" << std::endl; }
  19. break;
  20. case left: {std::cout << "left" << std::endl; }
  21. break;
  22. case right: {std::cout << "right" << std::endl; }
  23. break;
  24. default: {std::cout << "err404" << std::endl; }
  25. }
  26. }
  27. else
  28. {
  29. switch (key = toupper(key))
  30. {
  31. case 'D': {std::cout << "right" << std::endl;}
  32. break;
  33. case 'A': {std::cout << "left" << std::endl;}
  34. break;
  35. case 'W': {std::cout << "up" << std::endl;}
  36. break;
  37. case 'S': {std::cout << "down" << std::endl;}
  38. break;
  39. case '0':
  40. case esc: {std::cout << "out" << std::endl;}
  41. break;
  42. default: {std::cout << "err" << std::endl;}
  43. }
  44. }
  45. } while (key != esc && key != '0');
  46. return 0;//êîä çàâåðøåíèÿ ïðèëîæåíèÿ
  47. }