Advertisement
pcsiasop

Seman14MovilEnemigo

Jun 22nd, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.78 KB | None | 0 0
  1. #include <Windows.h>
  2. #include <iostream>
  3. #include <conio.h>
  4. #include <stdio.h>
  5. using namespace std;
  6. using namespace System;
  7.  
  8. #define ARRIBA     72    
  9. #define IZQUIERDA  75
  10. #define DERECHA    77
  11. #define ABAJO      80
  12. #define ESC        27
  13. #define ENTER      13
  14. #define CF 20
  15. #define CC 23
  16. int mapa[CF][CC];
  17. int backcolor = 0;
  18. int dir = 0;
  19. int anteriorpx, anteriorpy;
  20. int pxm = 8, pym = 10;
  21. int dx = 1, dy = 1;
  22. void gotoXY(int x, int y)
  23. {
  24.     HANDLE ventana;
  25.     ventana = GetStdHandle(STD_OUTPUT_HANDLE);
  26.     COORD punto;
  27.     punto.X = x;
  28.     punto.Y = y;
  29.     SetConsoleCursorPosition(ventana, punto);
  30. }
  31. void cargarMapa()
  32. {
  33.     int matTemporal[CF][CC] = { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  34.     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  35.     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  36.     { 0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0 },
  37.     { 0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0 },
  38.     { 0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0 },
  39.     { 0,0,0,0,0,1,0,0,0,0,1,1,1,0,0,0,0,0,0,1,0,0,0 },
  40.     { 0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0 },
  41.     { 0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0 },
  42.     { 0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  43.     { 0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  44.     { 0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  45.     { 0,0,0,0,0,1,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0 },
  46.     { 0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0 },
  47.     { 0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0 },
  48.     { 0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0 },
  49.     { 0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0 },
  50.     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  51.     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
  52.     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } };
  53.  
  54.     for (int i = 0; i < CF; i++)
  55.     {
  56.         for (int j = 0; j < CC; j++)
  57.         {
  58.             mapa[i][j] = matTemporal[i][j];
  59.         }
  60.     }
  61. }
  62. void pintarMapa()
  63. {
  64.     for (int i = 0; i < CF; i++) {
  65.         for (int j = 0; j < CC; j++)
  66.         {
  67.             gotoXY(j, i);
  68.             switch (mapa[i][j])
  69.             {
  70.             case  0:
  71.                 Console::ForegroundColor = ConsoleColor::Yellow;
  72.                 cout << (char)225;
  73.                 break;
  74.             case 1:
  75.                 Console::ForegroundColor = ConsoleColor(2);
  76.                 cout << (char)0;
  77.                 break;
  78.             }
  79.         }
  80.     }
  81. }
  82. void teclear() {
  83.     gotoXY(pym, pxm); cout << "*";
  84.     if (kbhit()) {
  85.         char tecla = getch();
  86.         switch (tecla) {
  87.         case ARRIBA:
  88.             if (mapa[pxm][pym] == 1)
  89.             {
  90.                 gotoXY(pym, pxm); cout << "*";
  91.                 Sleep(70);
  92.                 gotoXY(pym, pxm); cout << " ";
  93.                 pxm--;
  94.             }
  95.             else
  96.             {
  97.                 gotoXY(pym, pxm); cout << (char)225;
  98.                 pym = 10; pxm = 8;
  99.                 gotoXY(pym, pxm); cout << "*";
  100.             }
  101.             break;
  102.         case ABAJO:
  103.             if (mapa[pxm][pym] == 1)
  104.             {
  105.                 gotoXY(pym, pxm); cout << "*";
  106.                 Sleep(70);
  107.                 gotoXY(pym, pxm); cout << " ";
  108.                 pxm++;
  109.             }
  110.             else
  111.             {
  112.                 gotoXY(pym, pxm); cout << (char)225;
  113.                 pym = 10; pxm = 8;
  114.                 gotoXY(pym, pxm); cout << "*";
  115.             }
  116.             break;
  117.         case DERECHA:
  118.             if (mapa[pxm][pym] == 1)
  119.             {
  120.                 gotoXY(pym, pxm); cout << "*";
  121.                 Sleep(70);
  122.                 gotoXY(pym, pxm); cout << " ";
  123.                 pym++;
  124.             }
  125.             else
  126.             {
  127.                 gotoXY(pym, pxm); cout << (char)225;
  128.                 pym = 10; pxm = 8;
  129.                 gotoXY(pym, pxm); cout << "*";
  130.             }
  131.             break;
  132.         case IZQUIERDA:
  133.             if (mapa[pxm][pym] == 1)
  134.             {
  135.                 gotoXY(pym, pxm); cout << "*";
  136.                 Sleep(70);
  137.                 gotoXY(pym, pxm); cout << " ";
  138.                 pym--;
  139.             }
  140.             else
  141.             {
  142.                 gotoXY(pym, pxm); cout << (char)225;
  143.                 pym = 10; pxm = 8;
  144.                 gotoXY(pym, pxm); cout << "*";
  145.             }
  146.             break;
  147.         }
  148.     }
  149. }
  150.  
  151. void desplazar_movil_y_enemigo(int x, int y)
  152. {
  153.     int dy = -1;
  154.  
  155.  
  156.     do {
  157.         gotoXY(x, y); cout << "#";
  158.         Sleep(70);
  159.         gotoXY(x, y); cout << " ";
  160.         //ubicar el movil
  161.         teclear();
  162.  
  163.         if (y < 4) dy = 1;
  164.         if (y > 7) dy = -1;
  165.         y += dy;
  166.     } while (1);
  167.  
  168. }
  169.  
  170. void main()
  171. {
  172.     cargarMapa();
  173.     pintarMapa();
  174.     desplazar_movil_y_enemigo(19,8);
  175.  
  176.     system("pause");
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement