Advertisement
Guest User

Untitled

a guest
May 24th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3.  
  4. using namespace std;
  5. using namespace System;
  6.  
  7. #define ARRIBA 72
  8. #define IZQUIERDA 75
  9. #define DERECHA 77
  10. #define ABAJO 80
  11.  
  12.  
  13. void dibuja(int x, int y) {
  14.     Console::SetCursorPosition(x, y);
  15.     cout << (char)1;
  16. }
  17. int main() {
  18.     int c, x=5, y=5;
  19.     Console::Clear();
  20.     dibuja(x, y);
  21.    
  22.     while (true) {
  23.         if (kbhit()) {
  24.             c = getch();
  25.             c = toupper(c);
  26.             switch (c) {
  27.                 case 'W':
  28.                 case ARRIBA:
  29.                     y--;
  30.                     break;
  31.                 case 'S':
  32.                 case ABAJO:
  33.                     y++;
  34.                     break;
  35.                 case 'D':
  36.                 case DERECHA:
  37.                     x++;
  38.                     break;
  39.                 case 'A':
  40.                 case IZQUIERDA:
  41.                     x--;
  42.                     break;
  43.             }
  44.             Console::Clear();
  45.             dibuja(x, y);
  46.         }
  47.        
  48.     }
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement