Advertisement
Guest User

Untitled

a guest
May 15th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <windows.h>
  3. #include <conio.h>
  4. #define SIZEA 40
  5. #define SIZEB 108
  6.  
  7. char c;
  8. void cursorposition(int x, int y)
  9. {
  10. ::HANDLE hConsoleOut =::GetStdHandle( STDOUTPUTHANDLE );
  11. ::CONSOLECURSORINFO hCCI;
  12. ::GetConsoleCursorInfo( hConsoleOut, & hCCI );
  13. hCCI.bVisible = FALSE;
  14. ::SetConsoleCursorInfo( hConsoleOut, & hCCI );
  15. HANDLE h = GetStdHandle(STDOUTPUTHANDLE);
  16. WORD wOldColorAttrs;
  17. SetConsoleTextAttribute(h, BACKGROUNDBLUE | FOREGROUNDINTENSITY);
  18.  
  19. int i = 0;
  20. int j = 0;
  21. for (j = 8; j<SIZE_A-8; j++)
  22. {
  23.  
  24.  
  25. for (i = 8; i<SIZE_B-8; i++)
  26. {
  27.  
  28. COORD pos;
  29. pos.X = i;
  30. pos.Y = j;
  31. SetConsoleCursorPosition(h, pos);
  32. printf(" ");
  33. }
  34. }
  35.  
  36.  
  37.  
  38. CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
  39. SetConsoleTextAttribute(h, wOldColorAttrs);
  40. SetConsoleTextAttribute(h, BACKGROUND_GREEN | FOREGROUND_BLUE);
  41. COORD pos;
  42.  
  43. pos.X = x;
  44. pos.Y = y;
  45. SetConsoleCursorPosition(h, pos);
  46. printf(" ");
  47.  
  48.  
  49. }
  50.  
  51. void direction (char c)
  52. {
  53. int x=SIZEB/2, y=SIZEA/2;
  54. cursorposition(x, y);
  55.  
  56. while (1)
  57. {
  58. if (_kbhit())
  59. c = getch();
  60. switch (c)
  61. {
  62.  
  63. case 'w': y--;
  64. break;
  65. case 's': y++;
  66. break;
  67. case 'a': x--;
  68. break;
  69. case 'd': x++;
  70. break;
  71. case ' ': x=SIZE_B/2, y=SIZE_A/2;
  72. break;
  73.  
  74. }
  75. int xold=x,yold=y;
  76.  
  77. if (xold>=SIZE_B-8) x = 8;
  78. else if (xold<=8) x=SIZE_B-9;
  79. if (yold>=SIZE_A-8) y = 8;
  80. else if (yold<=8) y=SIZE_A-9;
  81.  
  82. cursorposition(x, y);
  83. }
  84.  
  85.  
  86. }
  87.  
  88. int main()
  89.  
  90. {
  91.  
  92. printf("\n\n\n\n\nW: UP S: DOWN A: LEFT D: RIGHT");
  93. char c;
  94. if (_kbhit())
  95. c = getch();
  96. direction(c);
  97. return 0;
  98.  
  99.  
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement