Advertisement
Razk2108

tf-progra2.0

Jun 23rd, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <windows.h>
  4. using namespace std;
  5. using namespace System;
  6. void Dibujar_mapa(int **mapa)
  7. {
  8.     for (int i = 0; i<25; i++)
  9.     {
  10.         for (int j = 0; j<80; j++)
  11.         {
  12.             if (mapa[i][j] == 0)
  13.                 cout << " ";
  14.  
  15.             if (mapa[i][j] == 1)
  16.             {
  17.                 Console::ForegroundColor = ConsoleColor::Black;
  18.                 cout << char(219);
  19.             }
  20.             if (mapa[i][j] == 2)
  21.             {
  22.                 Console::ForegroundColor = ConsoleColor::DarkBlue;
  23.                 cout << char(219);
  24.             }
  25.         }
  26.     }
  27. }
  28. void Mapa1(int **mapa)
  29. {
  30.     int matriz[25][80] = { { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2 },
  31.     { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,1 },
  32.     { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,1,1 },
  33.     { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1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,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
  48.     { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
  49.     { 1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 } };
  50.     for (int i = 0; i<25; i++)
  51.         for (int j = 0; j<80; j++)
  52.             mapa[i][j] = matriz[i][j];
  53.     Dibujar_mapa(mapa);
  54. }
  55. void Mapa2(int **mapa)
  56. {
  57.     int matriz[25][80] = { { 1,1,1,1,1,1,1,1,1,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,1,1,1,1,1,1,1,1 },
  58.     { 1,1,1,1,1,1,1,1,1,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,1,1,1,1,1,1,1,1 },
  59.     { 1,1,1,1,1,1,1,1,1,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,1,1,1,1,1,1,1,1 },
  60.     { 1,1,1,1,1,1,1,1,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1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,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1 },
  75.     { 1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1 },
  76.     { 1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1 } };
  77.     for (int i = 0; i<25; i++)
  78.         for (int j = 0; j<80; j++)
  79.             mapa[i][j] = matriz[i][j];
  80.     Dibujar_mapa(mapa);
  81. }
  82.  
  83. void borrarpersonaje(int x, int y)
  84. {
  85.     Console::SetCursorPosition(x, y);
  86.     cout << " ";
  87.     Console::SetCursorPosition(x+1, y);
  88.     cout << " ";
  89.     Console::SetCursorPosition(x, y+1);
  90.     cout << " ";
  91.     Console::SetCursorPosition(x+1, y+1);
  92.     cout << " ";
  93. }
  94.  
  95. void dibujarpersonaje(int x, int y)
  96. {
  97.     Console::SetCursorPosition(x, y);
  98.     Console::BackgroundColor = ConsoleColor::Black;
  99.     Console::ForegroundColor = ConsoleColor::Green;
  100.     cout << char(219);
  101.     Console::SetCursorPosition(x+1, y);
  102.     Console::BackgroundColor = ConsoleColor::Black;
  103.     Console::ForegroundColor = ConsoleColor::Green;
  104.     cout << char(219);
  105.     Console::SetCursorPosition(x, y+1);
  106.     Console::BackgroundColor = ConsoleColor::Black;
  107.     Console::ForegroundColor = ConsoleColor::Green;
  108.     cout << char(219);
  109.     Console::SetCursorPosition(x+1, y+1);
  110.     Console::BackgroundColor = ConsoleColor::Black;
  111.     Console::ForegroundColor = ConsoleColor::Green;
  112.     cout << char(219);
  113. }
  114.  
  115. void moverpersonaje(int &x, int &y, int dx, int dy, int **matriz)
  116. {
  117.     dx = dy = 0;
  118.     if (_kbhit())
  119.     {
  120.         char teclapresionada = _getch();
  121.         teclapresionada = toupper(teclapresionada);
  122.         switch (teclapresionada)
  123.         {
  124.         case 72: dy = -1; dx = 0; break;
  125.         case 80: dy = 1;  dx = 0; break;
  126.         case 75: dx = -1; dy = 0; break;
  127.         case 77: dx = 1;  dy = 0;
  128.         }
  129.     }
  130.     if (x + dx < 0 || x + dx>70 || (matriz[y][x + dx] == 2) || (matriz[y][x + dx] == 2))
  131.     {
  132.         dx = 0;
  133.     }
  134.     if (y + dy < 0 || y + dy>19 || (matriz[y + dy][x] == 2) || (matriz[y+dy][x] == 2))
  135.     {
  136.         dy = 0;
  137.     }
  138.     if (x + dx < 0 || x + dx>70 || (matriz[y][x + dx] == 0) || (matriz[y][x + dx] == 0))
  139.     {
  140.         dx = 0;
  141.     }
  142.     if (y + dy < 0 || y + dy>19 || (matriz[y + dy][x] == 0) || (matriz[y + dy][x] == 0))
  143.     {
  144.         dy = 0;
  145.     }
  146.     if (x+1 + dx < 0 || x+1 + dx>70 || (matriz[y][x+1 + dx] == 2) || (matriz[y][x+1 + dx] == 2))
  147.     {
  148.         dx = 0;
  149.     }
  150.     if (y + dy < 0 || y + dy>19 || (matriz[y + dy][x+1] == 2) || (matriz[y + dy][x+1] == 2))
  151.     {
  152.         dy = 0;
  153.     }
  154.     if (x+1 + dx < 0 || x+1 + dx>70 || (matriz[y][x+1 + dx] == 0) || (matriz[y][x+1 + dx] == 0))
  155.     {
  156.         dx = 0;
  157.     }
  158.     if (y + dy < 0 || y + dy>19 || (matriz[y + dy][x+1] == 0) || (matriz[y + dy][x+1] == 0))
  159.     {
  160.         dy = 0;
  161.     }
  162.     if (x + dx < 0 || x + dx>70 || (matriz[y+1][x + dx] == 2) || (matriz[y+1][x + dx] == 2))
  163.     {
  164.         dx = 0;
  165.     }
  166.     if (y+1 + dy < 0 || y+1 + dy>19 || (matriz[y+1 + dy][x] == 2) || (matriz[y+1 + dy][x] == 2))
  167.     {
  168.         dy = 0;
  169.     }
  170.     if (x + dx < 0 || x + dx>70 || (matriz[y+1][x + dx] == 0) || (matriz[y+1][x + dx] == 0))
  171.     {
  172.         dx = 0;
  173.     }
  174.     if (y+1 + dy < 0 || y+1 + dy>19 || (matriz[y+1 + dy][x] == 0) || (matriz[y+1 + dy][x] == 0))
  175.     {
  176.         dy = 0;
  177.     }
  178.     if (x+1 + dx < 0 || x+1 + dx>70 || (matriz[y+1][x+1 + dx] == 2) || (matriz[y+1][x+1 + dx] == 2))
  179.     {
  180.         dx = 0;
  181.     }
  182.     if (y+1 + dy < 0 || y+1 + dy>19 || (matriz[y+1 + dy][x+1] == 2) || (matriz[y+1 + dy][x+1] == 2))
  183.     {
  184.         dy = 0;
  185.     }
  186.     if (x+1 + dx < 0 || x+1 + dx>70 || (matriz[y+1][x+1 + dx] == 0) || (matriz[y+1][x+1 + dx] == 0))
  187.     {
  188.         dx = 0;
  189.     }
  190.     if (y+1 + dy < 0 || y+1 + dy>19 || (matriz[y+1 + dy][x+1] == 0) || (matriz[y+1 + dy][x+1] == 0))
  191.     {
  192.         dy = 0;
  193.     }
  194.     x = x + dx;
  195.     y = y + dy;
  196.     dibujarpersonaje(x, y);
  197.     Sleep(10);//retardo
  198.     borrarpersonaje(x, y);
  199. }
  200.  
  201. void controlador(int &xpersonaje, int &ypersonaje, int dx, int dy, int ** matriz)
  202. {
  203.     while (1)
  204.         moverpersonaje(xpersonaje, ypersonaje, dx, dy, matriz);
  205. }
  206. void main()
  207. {
  208.     Console::SetWindowSize(80, 26);
  209.     Console::CursorVisible = false;
  210.     int **matriz, xpersonaje, ypersonaje, dx, dy;
  211.     matriz = new int*[25];
  212.     for (int i = 0; i<25; i++)
  213.         matriz[i] = new int[80];
  214.     xpersonaje = 43;
  215.     ypersonaje = 12;
  216.     dx = dy = 0;
  217.     Mapa1(matriz);
  218.     controlador(xpersonaje, ypersonaje, dx, dy, matriz);
  219.     moverpersonaje(xpersonaje, ypersonaje, dx, dy, matriz);
  220.     _getch();
  221. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement