Advertisement
Catdisk

TF Progra

Sep 7th, 2016
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 37.98 KB | None | 0 0
  1. #include <conio.h>
  2. #include <stdio.h>
  3. #include <iostream>
  4. #include <stdlib.h>
  5. #include <time.h>
  6.  
  7. using namespace System;
  8. using namespace std;
  9.  
  10.  
  11. #define KEY_UP 72 // estos son los scancodes de las teclas direccionales, las uso en la funcion Captura()
  12. #define KEY_DOWN 80
  13. #define KEY_LEFT 75
  14. #define KEY_RIGHT 77
  15.  
  16. // estas son las declaraciones de las funciones. es bueno para ver todas de un vistazo.
  17. void Dibujante(int *menu_state, int *hp_jugador, int *cant_pociones, int *dmg, bool *tiene_llave, bool *uso_pocion, int *id_enemigo, int *hp_enemigo, int **matriz, int *fila, int *columna, int *nivel, int *pos_i, int *pos_j);
  18. //dibuja la pantalla del juego, llama la funcion ImprimirMatriz()
  19. void Estado(int *hp_jugador, int *cant_pociones, int *dmg, bool *tiene_llave, bool *uso_pocion);
  20. // dibuja el estado del jugador (HP, pociones, etc)
  21. void Texto(int *id_enemigo, int *hp_enemigo, int *dmg, bool *ouch, int *ataque);
  22. // dibuja el texto (lo que sucede cada turno), llama la funcion ImprimirEnemigo()
  23. void MenuPrincipal(int *menu_state, int *game_screen);
  24. // dibuja el menu principal
  25. void Captura(int *menu, bool *enter, int *scancode, bool *esc, int *status, bool *uso_pocion, int *id_enemigo, int *nivel, int *dir, int *to_draw, int *dmg, int *hp_jugador, bool *game_over);
  26. // captura las teclas presionadas
  27. void PantallaAyuda(int *game_screen);
  28. // dibuja el menu de ayuda
  29. void ImprimirEnemigo(int *id_enemigo, int *hp_enemigo);
  30. // imprime el tipo de enemigo y el hp, segun el valor de *id_enemigo
  31. void GenerarMatriz(int **display, int **mapa, int *fila, int *columna);
  32. // le asigna valores a una matriz
  33. int** CrearMatriz(int *fila, int *columna);
  34. // crea una matriz del tamano *fila x *columna
  35. void ImprimirMatriz(int **display, int *fila, int *columna);
  36. // imprime la matriz **display
  37. int** GenerarPieza(int *id_pieza);
  38. // crea y genera una matriz de 5 x 5 segun mapa[][] (*id_pieza)
  39. void GenerarMapa(int **mapa, int *fila, int *columna, int *nivel);
  40. // genera una matriz con los valores *id_pieza (las dimensiones de la matriz dada tienen que ser de (*fila / 5) x (*columna / 5)
  41. void RotarPieza(int **pieza, int *dir);
  42. /* rota la pieza
  43. *dir | grados
  44.  0        0
  45.  1       90
  46.  2      180
  47.  3      270    */
  48. void ArmarDisplay(int i, int j, int **pieza, int **display);
  49. // "arma" el display con cada pieza segun el mapa
  50. void InteractuarConPersonaje(int **display, int *pos_i, int *pos_j, int *to_draw, int *nivel, bool *tiene_llave, int *cant_pociones, int *dmg, int *id_enemigo, int *hp_enemigo, int *ataque, bool *ouch, int *hp_jugador, bool *game_over);
  51. // lee e interactua con el personaje segun la casilla donde cae
  52. int NumeroAleatorio(int de, int hasta);
  53. // genera un int aleatorio en un rango establecio por "de" y "hasta"
  54. void Ganaste();
  55. // winscreen
  56. void Perdiste();
  57. // killscreen
  58.  
  59. // aqui comienzan las funciones
  60. void Dibujante(int *menu_state, int *hp_jugador, int *cant_pociones, int *dmg, bool *tiene_llave, bool *uso_pocion, int *id_enemigo, int *hp_enemigo, int **matriz, int *fila, int *columna, int *nivel, int *pos_i, int *pos_j)
  61. {
  62.     char lo = 201;
  63.     char hori = 205;
  64.     char ro = 187;
  65.     char verti = 186;
  66.     char ru = 188;
  67.     char lu = 200;
  68.     char oT = 203;
  69.     char uT = 202;
  70.     char lT = 204;
  71.     char rT = 185;
  72.     char space = 255;
  73.     bool sigue = true;
  74.  
  75.     Console::Clear();
  76.  
  77.     ImprimirMatriz(matriz, fila, columna);
  78.  
  79.     for (int i = 0; i < *fila && sigue; i++)
  80.     {
  81.         for (int j = 0; j < *columna && sigue; j++)
  82.         {
  83.             if ((matriz[i][j] % 10) == 9)
  84.             {
  85.                 *pos_i = i;
  86.                 *pos_j = j;
  87.                 sigue = false;
  88.             }
  89.         }
  90.     }
  91.  
  92.     for (int i = 0; i < 24; i++)
  93.     {
  94.         for (int j = 0; j < 51; j++)
  95.         {
  96.             Console::SetCursorPosition(j, i);
  97.  
  98.             if (j == 0)
  99.             {
  100.                 if (i == 0)
  101.                     cout << lo;
  102.                 else if (i == 2)
  103.                     cout << lT;
  104.                 else if (i == 23)
  105.                     cout << lu;
  106.                 else
  107.                     cout << verti;
  108.             }
  109.             if (j > 0)
  110.             {
  111.                 if (i == 0 || i == 2 || i == 23)
  112.                     cout << hori;
  113.             }
  114.             if (j == 2 && i == 1)
  115.             {
  116.                 cout << "Nivel: ";
  117.  
  118.                 if (*nivel != 0)
  119.                     cout << *nivel;
  120.                 else
  121.                 {
  122.                     Console::ForegroundColor = ConsoleColor::DarkGreen;
  123.                     cout << "Debug";
  124.                     Console::ForegroundColor = ConsoleColor::Gray;
  125.                 }
  126.             }
  127.         }
  128.     }
  129.     for (int j = 0; j < 24; j++) // fila de 1 a 24
  130.     {
  131.         for (int i = 0; i < 29; i++) // HUD
  132.         {
  133.             Console::SetCursorPosition(i + 51, j);
  134.  
  135.             if (j == 0) // linea superior
  136.             {
  137.                 if (i == 0)
  138.                     cout << oT;
  139.                 else if (i == 28)
  140.                     cout << ro;
  141.                 else
  142.                     cout << hori;
  143.             }
  144.             else if (j == 2 && i == 0)
  145.             {
  146.                 cout << rT;
  147.             }
  148.             else if (j == 10) // linea del medio
  149.             {
  150.                 if (i == 0)
  151.                     cout << lT;
  152.                 else if (i == 28)
  153.                     cout << rT;
  154.                 else
  155.                     cout << hori;
  156.             }
  157.             else if (j == 23) // linea inferior
  158.             {
  159.                 if (i == 0)
  160.                     cout << uT;
  161.                 else if (i == 28)
  162.                     cout << ru;
  163.                 else
  164.                     cout << hori;
  165.             }
  166.             else if (i == 0 || i == 28)
  167.                 cout << verti;
  168.         }
  169.     }
  170.     *menu_state = 1;
  171. }
  172.  
  173. void Estado(int *hp_jugador, int *cant_pociones, int *dmg, bool *tiene_llave, bool *uso_pocion)  // Estado del jugador
  174. {
  175.     char verti = 186;
  176.     char space = 255;
  177.     char block = 219;
  178.     char points = 176;
  179.  
  180.     if (*uso_pocion)
  181.     {
  182.         if (*hp_jugador < 5 && *cant_pociones > 0)
  183.         {
  184.             *hp_jugador += 1;
  185.             *cant_pociones -= 1;
  186.         }
  187.         *uso_pocion = false;
  188.     }
  189.  
  190.     for (int j = 0; j < 24; j++)
  191.     {
  192.         for (int i = 0; i < 29; i++)
  193.         {
  194.             Console::SetCursorPosition(i + 51, j);
  195.  
  196.             if (i == 2 && j == 2) // 2da linea: HP
  197.             {
  198.                 cout << "HP: " << *hp_jugador << "/5";
  199.             }
  200.             else if (i == 11 && j == 2)
  201.             {
  202.                 Console::ForegroundColor = ConsoleColor::DarkGray;
  203.                 for (int z = 0; z < 15 - (*hp_jugador * 3); z++)
  204.                     cout << points;
  205.                 Console::ForegroundColor = ConsoleColor::DarkRed;
  206.                 for (int z = 0; z < *hp_jugador * 3; z++)
  207.                     cout << block;
  208.                 Console::ForegroundColor = ConsoleColor::Gray;
  209.             }
  210.             else if (i == 2 && j == 4) // 4ta linea: ataque
  211.             {
  212.                 cout << "Nivel de Corrupcion: +" << *dmg;
  213.             }
  214.             else if (i == 2 && j == 6) // 6ta linea: pociones
  215.             {
  216.                 cout << "Pointers: " << *cant_pociones;
  217.             }
  218.             else if (i == 2 && j == 8) // 8va linea: tiene la llave?
  219.             {
  220.                 if (*tiene_llave)
  221.                 {
  222.                     cout << "Tienes la ";
  223.                     Console::ForegroundColor = ConsoleColor::Yellow;
  224.                     cout << "LLAVE";
  225.                     Console::ForegroundColor = ConsoleColor::Gray;
  226.                     cout << "!   ";
  227.                 }
  228.  
  229.                 else
  230.                 {
  231.                     cout << "No tienes la ";
  232.                     Console::ForegroundColor = ConsoleColor::Yellow;
  233.                     cout << "LLAVE";
  234.                     Console::ForegroundColor = ConsoleColor::Gray;
  235.                 }
  236.             }
  237.         }
  238.     }
  239.  
  240.  
  241. }
  242.  
  243. void Texto(int *id_enemigo, int *hp_enemigo, int *dmg, bool *ouch, int *ataque)
  244. {
  245.     for (int j = 0; j < 24; j++)
  246.     {
  247.         for (int i = 0; i < 29; i++)
  248.         {
  249.             Console::SetCursorPosition(i + 51, j);
  250.  
  251.  
  252.                 if (j == 12 && i == 2)
  253.                 {
  254.                     cout << "Te ataca";
  255.                 }
  256.                 else if (j == 13 && i == 2)
  257.                 {
  258.                     ImprimirEnemigo(id_enemigo, hp_enemigo);
  259.                 }
  260.                 else if (j == 14 && i == 5)
  261.                 {
  262.                     cout << "con ";
  263.                     if (*hp_enemigo < 10)
  264.                         cout << '0';
  265.                     cout << *hp_enemigo << " HP! ";
  266.                 }
  267.                 else if (j == 16 && i == 2)
  268.                 {
  269.                     cout << "Tu atacas con ";
  270.                     if (*ataque < 10)
  271.                         cout << '0';
  272.                     cout << *ataque << " !";
  273.                 }
  274.                 else if (j == 18 && i == 2)
  275.                 {
  276.                     ImprimirEnemigo(id_enemigo, hp_enemigo);
  277.                 }
  278.                 else if (j == 19 && i == 5)
  279.                 {
  280.                     if (*ouch)
  281.                     {
  282.                         cout << "explota y te quita 1HP!";
  283.                         *ouch = false;
  284.                     }
  285.                     else
  286.                     {
  287.                         cout << "explota!               ";
  288.                     }
  289.                 }
  290.            
  291.         }
  292.     }
  293. }
  294.  
  295. void ImprimirEnemigo(int *id_enemigo, int *hp_enemigo)
  296. {
  297.     switch (*id_enemigo)
  298.     {
  299.     case 9:
  300.         cout << "int         ";
  301.         *hp_enemigo = 5;
  302.         break;
  303.     case 1:
  304.         cout << "double      ";
  305.         *hp_enemigo = 6;
  306.         break;
  307.     case 2:
  308.         cout << "string      ";
  309.         *hp_enemigo = 8;
  310.         break;
  311.     case 3:
  312.         cout << "function()  ";
  313.         *hp_enemigo = 7;
  314.         break;
  315.     case 4:
  316.         cout << "class       ";
  317.         *hp_enemigo = 10;
  318.         break;
  319.     case 5:
  320.         cout << "library     ";
  321.         *hp_enemigo = 13;
  322.         break;
  323.     case 6:
  324.         cout << "cmd.exe     ";
  325.         *hp_enemigo = 12;
  326.         break;
  327.     case 7:
  328.         cout << "rootmdm.sys ";
  329.         *hp_enemigo = 12;
  330.         break;
  331.     case 8:
  332.         cout << "system32    ";
  333.         *hp_enemigo = 15;
  334.         break;
  335.     }
  336. }
  337.  
  338. void MenuPrincipal(int *menu_state, int *game_screen)
  339. {
  340.     Console::Clear();
  341.  
  342.     for (int j = 0; j < 16; j++)
  343.     {
  344.         Console::SetCursorPosition(25, j + 2);
  345.         switch (j)
  346.         {
  347.         case 0:
  348.             cout << " _____ _____ _____ _____ _____ ";
  349.             break;
  350.         case 1:
  351.             cout << "|  _  |   __|     |     |     |";
  352.             break;
  353.         case 2:
  354.             cout << "|     |__   |   --|-   -|-   -|";
  355.             break;
  356.         case 3:
  357.             cout << "|__|__|_____|_____|_____|_____|";
  358.             break;
  359.         case 4:
  360.             Console::ForegroundColor = ConsoleColor::DarkRed;
  361.             cout << "    _                         ";
  362.             break;
  363.         case 5:
  364.             cout << "  _| |_ _ ___ ___ ___ ___ ___ ";
  365.             break;
  366.         case 6:
  367.             cout << " | . | | |   | . | -_| . |   |";
  368.             break;
  369.         case 7:
  370.             cout << " |___|___|_|_|_  |___|___|_|_|";
  371.             break;
  372.         case 8:
  373.             cout << "             |___|            ";
  374.             Console::ForegroundColor = ConsoleColor::Gray;
  375.             break;
  376.         case 11:
  377.             if (*menu_state == 0)
  378.             {
  379.                 Console::BackgroundColor = ConsoleColor::DarkRed;
  380.                 Console::ForegroundColor = ConsoleColor::Black;
  381.             }
  382.             cout << "[  run hack.bat   ]";
  383.             Console::BackgroundColor = ConsoleColor::Black;
  384.             Console::ForegroundColor = ConsoleColor::Gray;
  385.             break;
  386.         case 13:
  387.             if (*menu_state == 1)
  388.             {
  389.                 Console::BackgroundColor = ConsoleColor::DarkRed;
  390.                 Console::ForegroundColor = ConsoleColor::Black;
  391.             }
  392.             cout << "[   README.txt    ]";
  393.             Console::BackgroundColor = ConsoleColor::Black;
  394.             Console::ForegroundColor = ConsoleColor::Gray;
  395.             break;
  396.         case 15:
  397.             if (*menu_state == 2)
  398.             {
  399.                 Console::BackgroundColor = ConsoleColor::DarkRed;
  400.                 Console::ForegroundColor = ConsoleColor::Black;
  401.             }
  402.             cout << "[ system.shutdown ]";
  403.             Console::BackgroundColor = ConsoleColor::Black;
  404.             Console::ForegroundColor = ConsoleColor::Gray;
  405.             break;
  406.         default:
  407.             break;
  408.         }
  409.     }
  410.     *game_screen = 0;
  411. }
  412.  
  413. void PantallaAyuda(int *game_screen)
  414. {
  415.     char hori = 205;
  416.     char verti = 186;
  417.     char lo = 201;
  418.     char ro = 187;
  419.     char ru = 188;
  420.     char lu = 200;
  421.     char lT = 204;
  422.     char rT = 185;
  423.     char jugador = 254;
  424.     char llave = 'L';
  425.     char tesoro = 'T';
  426.     char salida = 'S';
  427.     char pared = 219;
  428.     char piso = 176;
  429.  
  430.     Console::Clear();
  431.  
  432.     for (int j = 0; j < 24; j++) // fila
  433.     {
  434.         for (int i = 0; i < 80; i++) // columna
  435.         {
  436.             Console::SetCursorPosition(i, j);
  437.  
  438.             if (j == 0)
  439.             {
  440.                 if (i == 0)
  441.                     cout << lo;
  442.                 else if (i == 79)
  443.                     cout << ro;
  444.                 else
  445.                     cout << hori;
  446.             }
  447.             if (j > 0 && j < 15)
  448.             {
  449.                 if (i == 0 || i == 79)
  450.                     cout << verti;
  451.                 else if (i == 4)
  452.                 {
  453.                     switch (j - 3)
  454.                     {
  455.                     case 0:
  456.                         Console::ForegroundColor = ConsoleColor::Yellow;
  457.                         cout << llave;
  458.                         break;
  459.                     case 2:
  460.                         Console::ForegroundColor = ConsoleColor::Magenta;
  461.                         cout << tesoro;
  462.                         break;
  463.                     case 4:
  464.                         Console::ForegroundColor = ConsoleColor::Green;
  465.                         cout << salida;
  466.                         break;
  467.                     case 6:
  468.                         Console::ForegroundColor = ConsoleColor::Red;
  469.                         cout << (char)64;
  470.                         break;
  471.                     case 8:
  472.                         Console::ForegroundColor = ConsoleColor::Gray;
  473.                         cout << pared << piso << piso << piso << pared;
  474.                         break;
  475.                     case 10:
  476.                         Console::ForegroundColor = ConsoleColor::Cyan;
  477.                         cout << jugador;
  478.                         break;
  479.                     default:
  480.                         break;
  481.                     }
  482.                     Console::ForegroundColor = ConsoleColor::Gray;
  483.                 }
  484.  
  485.                 else if (i == 17)
  486.                 {
  487.                     switch (j - 3)
  488.                     {
  489.                     case 0:
  490.                         cout << "Llave                  (nesecitaras esto)";
  491.                         break;
  492.                     case 2:
  493.                         cout << "Tesoro                 (a.k.a datos desprotegidos)";
  494.                         break;
  495.                     case 4:
  496.                         cout << "Salida del Nivel       (esto todavia sigue!?)";
  497.                         break;
  498.                     case 6:
  499.                         cout << "Enemigo                (cuidado, antivirus!)";
  500.                         break;
  501.                     case 8:
  502.                         cout << "Memoria                (totalmente seguro, confia en mi ...)";
  503.                         break;
  504.                     case 10:
  505.                         cout << "hack.bat               (efectivamente, este eres tu)";
  506.                         break;
  507.                     default:
  508.                         break;
  509.                     }
  510.                 }
  511.             }
  512.             if (j == 15)
  513.             {
  514.                 if (i == 0)
  515.                     cout << lT;
  516.                 else if (i == 79)
  517.                     cout << rT;
  518.                 else
  519.                     cout << hori;
  520.             }
  521.             if (j > 15 && j < 23)
  522.             {
  523.                 if (i == 0 || i == 79)
  524.                     cout << verti;
  525.                 else if (i == 4)
  526.                 {
  527.                     Console::ForegroundColor = ConsoleColor::White;
  528.                     switch (j - 17)
  529.                     {
  530.                     case 0:
  531.                         cout << "Arrow Keys";
  532.                         break;
  533.                     case 2:
  534.                         cout << 'P';
  535.                         break;
  536.                     case 4:
  537.                         cout << "Esc";
  538.                         break;
  539.                     }
  540.                     Console::ForegroundColor = ConsoleColor::Gray;
  541.                 }
  542.  
  543.                 else if (i == 17)
  544.                 {
  545.                     switch (j - 17)
  546.                     {
  547.                     case 0:
  548.                         cout << "para moverse                 (...duh)";
  549.                         break;
  550.                     case 2:
  551.                         cout << "para acceder a un puntero    (si te quedan algunos)";
  552.                         break;
  553.                     case 4:
  554.                         cout << "para salir al Menu Principal (no te culpo si me dejas D,: )";
  555.                         break;
  556.                     }
  557.                 }
  558.             }
  559.             if (j == 23)
  560.             {
  561.                 if (i == 0)
  562.                     cout << lu;
  563.                 else if (i == 79)
  564.                     cout << ru;
  565.                 else
  566.                     cout << hori;
  567.             }
  568.  
  569.         }
  570.     }
  571.     *game_screen = 2;
  572. }
  573.  
  574. void Captura(int *menu, bool *enter, int *scancode, bool *esc, int *status, bool *uso_pocion, int *id_enemigo, int *nivel, int *dir, int *to_draw, int *dmg, int *hp_jugador, bool *game_over)
  575. {
  576.     switch ((*scancode = _getch()))
  577.     {
  578.     case KEY_UP:
  579.         //cout << endl << "Up" << endl;
  580.         if (*menu != 0 && *status == 0)
  581.             *menu -= 1;
  582.         else if (*status == 0)
  583.             *menu = 2;
  584.         *dir = 1;
  585.         *to_draw += 1;
  586.         break;
  587.     case KEY_DOWN:
  588.         //cout << endl << "Down" << endl;
  589.         if (*menu != 2 && *status == 0)
  590.             *menu += 1;
  591.         else if (*status == 0)
  592.             *menu = 0;
  593.         *dir = 3;
  594.         *to_draw += 1;
  595.         break;
  596.     case KEY_LEFT:
  597.         //cout << endl << "Left" << endl;
  598.         *dir = 4;
  599.         *to_draw += 1;
  600.         break;
  601.     case KEY_RIGHT:
  602.         //cout << endl << "Right" << endl;
  603.         *dir = 2;
  604.         *to_draw += 1;
  605.         break;
  606.     case 13:
  607.         //cout << endl << "Enter" << endl;
  608.         *enter = true;
  609.         *to_draw += 10;
  610.         break;
  611.     case 27:
  612.         *esc = true;
  613.         break;
  614.     case 112: // 'p'
  615.         if (*status == 1)
  616.         {
  617.             *uso_pocion = true;
  618.             *to_draw += 100;
  619.         }
  620.         break;
  621.     case 97: // 'a'
  622.         if (*id_enemigo != 8 && *status == 1)
  623.             *id_enemigo += 1;
  624.         else if (*status == 1)
  625.             *id_enemigo = 0;
  626.         *to_draw += 10;
  627.         break;
  628.     case 111: // 'o'
  629.         *nivel += 1;
  630.         if (*nivel > 8)
  631.             *nivel = 0;
  632.         *to_draw += 1111;
  633.         break;
  634.     case 105: // 'i'
  635.         *dmg += 1;
  636.         *to_draw += 100;
  637.         break;
  638.     case 117: // 'u'
  639.         *hp_jugador -= 1;
  640.         if (*hp_jugador < 0)
  641.             *hp_jugador = 0;
  642.         *to_draw += 100;
  643.         break;
  644.     case 121: // 'y'
  645.         *game_over = true;
  646.     default:
  647.         //cout << endl << *scancode << endl;
  648.         break;
  649.     }
  650.  
  651.  
  652.     if (*esc && *status == 1 || *status == 2)
  653.     {
  654.         *status = 0;
  655.         *esc = false;
  656.     }
  657.     if (*status == 0)
  658.     {
  659.         if (*enter && *menu == 0)
  660.             *status = 1;
  661.  
  662.         if (*enter && *menu == 1)
  663.             *status = 2;
  664.  
  665.         if (*enter && *menu == 2)
  666.             *status = 3;
  667.  
  668.         *enter = false;
  669.     }
  670. }
  671.  
  672. int** CrearMatriz(int *fila, int *columna)
  673. {
  674.     int **auxMatrix = new int *[*fila];
  675.     for (int i = 0; i < *fila; i++)
  676.     {
  677.         auxMatrix[i] = new int[*columna];
  678.     }
  679.     return auxMatrix;
  680. }
  681.  
  682. void GenerarMatriz(int **display, int **mapa, int *fila_mapa, int *columna_mapa) // cambia test por &mapa[i][j]
  683. {
  684.     int test = 10;
  685.     for (int i = 0; i < *fila_mapa; i++)
  686.     {
  687.         for (int j = 0; j < *columna_mapa; j++)
  688.         {
  689.             int **pieza = GenerarPieza(&mapa[i][j]);
  690.  
  691.             RotarPieza(pieza, &mapa[i][j]);
  692.  
  693.             ArmarDisplay(i, j, pieza, display);
  694.  
  695.             Console::SetCursorPosition(j * 2, i + 24);
  696.             cout << mapa[i][j];
  697.         }
  698.     }
  699. }
  700.  
  701. void ArmarDisplay(int i, int j, int **pieza, int **display)
  702. {
  703.     int rango_i = i * 5;
  704.     int rango_j = j * 5;
  705.  
  706.     for (int m = rango_i; m < (rango_i + 5); m++)
  707.     {
  708.         for (int n = rango_j; n < (rango_j + 5); n++)
  709.         {
  710.             display[m][n] = pieza[m % 5][n % 5];
  711.         }
  712.     }
  713. }
  714.  
  715. void ImprimirMatriz(int **matriz, int *fila, int *columna)
  716. {
  717.     for (int i = 0; i < *fila; i++)
  718.     {
  719.         for (int j = 0; j < *columna; j++)
  720.         {
  721.             Console::SetCursorPosition(j + 1, i + 3);
  722.             /*
  723.             1 = pared safe
  724.             2 = piso safe
  725.             3 = pared danger
  726.             4 = piso danger
  727.             5 = jugador
  728.             6 = llave
  729.             7 = tesoro
  730.             8 = salida
  731.             9 = entrada
  732.             10 = enemigo
  733.             */
  734.             switch (matriz[i][j])
  735.             {
  736.             case 1:
  737.                 cout << (char)219;
  738.                 break;
  739.             case 2:
  740.                 cout << (char)176;
  741.                 break;
  742.             case 3:
  743.                 Console::ForegroundColor = ConsoleColor::DarkRed;
  744.                 cout << (char)219;
  745.                 break;
  746.             case 4:
  747.                 Console::ForegroundColor = ConsoleColor::DarkRed;
  748.                 cout << (char)176;
  749.                 break;
  750.             case 5:
  751.                 Console::ForegroundColor = ConsoleColor::Cyan;
  752.                 cout << (char)254;
  753.                 break;
  754.             case 6:
  755.                 Console::ForegroundColor = ConsoleColor::Yellow;
  756.                 cout << 'L';
  757.                 break;
  758.             case 7:
  759.                 Console::ForegroundColor = ConsoleColor::Magenta;
  760.                 cout << 'T';
  761.                 break;
  762.             case 8:
  763.                 Console::ForegroundColor = ConsoleColor::Green;
  764.                 cout << 'S';
  765.                 break;
  766.             case 9:
  767.                 Console::ForegroundColor = ConsoleColor::Red;
  768.                 cout << 'E';
  769.                 break;
  770.             case 10:
  771.                 Console::ForegroundColor = ConsoleColor::Red;
  772.                 cout << (char)64;
  773.             }
  774.             Console::ForegroundColor = ConsoleColor::Gray;
  775.         }
  776.     }
  777. }
  778.  
  779. int** GenerarPieza(int *id_pieza)
  780. {
  781.     /*
  782.     0 = nada
  783.     1 = pared safe
  784.     2 = piso safe
  785.     3 = pared danger
  786.     4 = piso danger
  787.     5 = jugador
  788.     6 = llave
  789.     7 = tesoro
  790.     8 = salida
  791.     9 = entrada
  792.     10 = enemigo
  793.     */
  794.     int tipo = *id_pieza / 1000; // decomposicion del primer digito
  795.     int item = *id_pieza % 10; // decomposicion del untimo digito
  796.     int dim = 5;
  797.  
  798.     int **aux = CrearMatriz(&dim, &dim);
  799.  
  800.     for (int i = 0; i < 5; i++)
  801.     {
  802.         for (int j = 0; j < 5; j++)
  803.         {
  804.             switch (tipo)
  805.             {
  806.             case 1: // cruz
  807.                 if (j == 0 || j == 4)
  808.                 {
  809.                     if (i == 0 || i == 4)
  810.                         aux[i][j] = 1;
  811.                     else
  812.                         aux[i][j] = 2;
  813.                 }
  814.                 else
  815.                     aux[i][j] = 2;
  816.                 break;
  817.             case 2: // L
  818.                 if (j == 0)
  819.                     aux[i][j] = 1;
  820.                 else if (i == 4)
  821.                     aux[i][j] = 1;
  822.                 else if (i == 0 && j == 4)
  823.                     aux[i][j] = 1;
  824.                 else
  825.                     aux[i][j] = 2;
  826.                 break;
  827.             case 3: // recta
  828.                 if (j == 0 || j == 4)
  829.                     aux[i][j] = 1;
  830.                 else
  831.                     aux[i][j] = 2;
  832.                 break;
  833.             case 4: // callejon
  834.                 if (j == 0 || j == 4)
  835.                     aux[i][j] = 1;
  836.                 else if (i == 4)
  837.                     aux[i][j] = 1;
  838.                 else
  839.                     aux[i][j] = 2;
  840.                 break;
  841.             case 5: // T
  842.                 if (i == 4)
  843.                     aux[i][j] = 1;
  844.                 else if (i == 0 && (j == 0 || j == 4))
  845.                     aux[i][j] = 1;
  846.                 else
  847.                     aux[i][j] = 2;
  848.                 break;
  849.             case 6: // vacio
  850.                 aux[i][j] = 0;
  851.             }
  852.         }
  853.     }
  854.     switch (item)
  855.     {
  856.     case 0:
  857.         break;
  858.     case 1:
  859.         aux[2][2] = 9;
  860.         break;
  861.     case 2:
  862.         aux[2][2] = 8;
  863.         break;
  864.     case 3:
  865.         aux[2][2] = 6;
  866.         break;
  867.     case 4:
  868.         aux[2][2] = 7;
  869.         break;
  870.     case 5:
  871.         aux[2][2] = 10;
  872.         break;
  873.     }
  874.     return aux;
  875. }
  876.  
  877. void GenerarMapa(int **mapa, int *fila, int *columna, int *nivel) // *columna = *columna_mapa, *fila = *fila_mapa
  878. {
  879.  
  880.     for (int i = 0; i < *fila; i++)
  881.     {
  882.         for (int j = 0; j < *columna; j++)
  883.         {
  884.             mapa[i][j] = 6000;
  885.         }
  886.     }
  887.  
  888.     switch (*nivel)
  889.     {
  890.     case 0: // debug
  891.         for (int i = 0; i < *fila; i++)
  892.         {
  893.             for (int j = 0; j < *columna; j++)
  894.             {
  895.                 if (i == 0)
  896.                 {
  897.                     if (j > 0 && j < 9)
  898.                         mapa[i][j] = 3120;
  899.                 }
  900.                 else
  901.                     mapa[i][j] = 6000;
  902.             }
  903.         }
  904.         mapa[0][0] = 4121;
  905.         mapa[0][1] += 4;
  906.         mapa[0][9] = 4322;
  907.         mapa[0][3] += 3;
  908.         mapa[0][5] += 5;
  909.         break;
  910.     case 1: // mapa 1 (prologo)
  911.         for (int i = 0; i < *fila; i++)
  912.         {
  913.             for (int j = 0; j < *columna; j++)
  914.             {
  915.                 if (i == 0)
  916.                 {
  917.                     if (j > 2 && j < 7)
  918.                         mapa[i][j] = 3120;
  919.                 }
  920.                 if (j == 2 || j == 7)
  921.                 {
  922.                     if (i == 1 || i == 2)
  923.                         mapa[i][j] = 3020;
  924.                 }
  925.                 if (j == 1 || j == 8)
  926.                 {
  927.                     if(i == 3)
  928.                         mapa[i][j] = 3120;
  929.                 }
  930.             }
  931.         }
  932.         mapa[3][2] = 2325;
  933.         mapa[0][2] = 2124;
  934.         mapa[0][7] = 2225;
  935.         mapa[3][7] = 2023;
  936.         mapa[3][0] = 4121;
  937.         mapa[3][9] = 4322;
  938.         break;
  939.     case 2: //mapa 2
  940.         for (int i = 0; i < *fila; i++)
  941.         {
  942.             for (int j = 0; j < *columna; j++)
  943.             {
  944.                 if (i == 3)
  945.                 {
  946.                     mapa[3][0] = 4121; //ENTRADA
  947.                     mapa[3][1] = 5020;
  948.                     mapa[3][9] = 2324;
  949.  
  950.                     if (j > 1 && j < 9)
  951.                     {
  952.                         mapa[i][j] = 3120;
  953.                     }
  954.                 }
  955.  
  956.                 if (i == 2)
  957.                 {
  958.                     mapa[2][0] = 4123;
  959.                     mapa[2][1] = 2225;
  960.                     mapa[2][9] = 3020;
  961.  
  962.                     if (j == 3 || j == 6)
  963.                     {
  964.                         mapa[i][j] = 3120;
  965.                     }
  966.  
  967.                     if (j == 2 || j == 5)
  968.                     {
  969.                         mapa[i][j] = 2020;
  970.                     }
  971.  
  972.                     if (j == 4 || j == 7)
  973.                     {
  974.                         mapa[i][j] = 2320;
  975.                     }
  976.                 }
  977.  
  978.                 if (i == 1)
  979.                 {
  980.                     mapa[1][0] = 2020;
  981.                     mapa[1][6] = 4024;
  982.  
  983.                     if (j == 1 || j == 8)
  984.                     {
  985.                         mapa[i][j] = 3120;
  986.                     }
  987.  
  988.                     if (j == 2 || j == 5 || j == 9)
  989.                     {
  990.                         mapa[i][j] = 2220;
  991.                     }
  992.  
  993.                     if (j == 4 || j == 7)
  994.                     {
  995.                         mapa[i][j] = 2125;
  996.                     }
  997.                 }
  998.  
  999.                 if (i == 0)
  1000.                 {
  1001.                     mapa[0][9] = 4322; //SALIDA
  1002.                     mapa[0][6] = 5225;
  1003.                     mapa[0][0] = 2120;
  1004.                     if (j > 0 && j < 6 || j == 7 || j == 8)
  1005.                     {
  1006.                         mapa[i][j] = 3120;
  1007.                     }
  1008.                 }
  1009.             }
  1010.  
  1011.         }
  1012.         break;
  1013.  
  1014.     case 3: //mapa 3
  1015.         for (int i = 0; i < *fila; i++)
  1016.         {
  1017.             for (int j = 0; j < *columna; j++)
  1018.             {
  1019.                 if (i == 0)
  1020.                 {
  1021.                     mapa[0][0] = 2125;
  1022.                     mapa[0][1] = 3125;
  1023.                     mapa[0][2] = 4324;
  1024.                     mapa[0][3] = 4223;
  1025.                     mapa[0][6] = 4124;
  1026.  
  1027.                     if (j == 0 || j == 4 || j == 8)
  1028.                     {
  1029.                         mapa[i][j] = 2120;
  1030.                     }
  1031.  
  1032.                     if (j == 5 || j == 7 || j == 9)
  1033.                     {
  1034.                         mapa[i][j] = 2220;
  1035.                     }
  1036.                 }
  1037.  
  1038.                 if (i == 1)
  1039.                 {
  1040.                     mapa[1][0] = 2020;
  1041.                     mapa[1][1] = 2220;
  1042.                     mapa[1][2] = 2120;
  1043.                     mapa[1][5] = 5120;
  1044.                     mapa[1][6] = 3120;
  1045.  
  1046.                     if (j == 3 || j == 7)
  1047.                     {
  1048.                         mapa[i][j] = 2325;
  1049.                     }
  1050.  
  1051.                     if (j == 4 || j == 8 || j == 9)
  1052.                     {
  1053.                         mapa[i][j] = 3020;
  1054.                     }
  1055.                 }
  1056.  
  1057.                 if (i == 2)
  1058.                 {
  1059.                     mapa[2][0] = 4121; //ENTRADA
  1060.                     mapa[2][1] = 5320;
  1061.                     mapa[2][7] = 2120;
  1062.                     mapa[2][8] = 2320;
  1063.                     mapa[2][9] = 3025;
  1064.  
  1065.                     if (j == 2 || j == 4 || j == 5)
  1066.                     {
  1067.                         mapa[i][j] = 3020;
  1068.                     }
  1069.                 }
  1070.  
  1071.                 if (i == 3)
  1072.                 {
  1073.                     mapa[3][8] = 4122; //SALIDA
  1074.                     mapa[3][2] = 5020;
  1075.  
  1076.                     if (j == 1 || j == 5)
  1077.                     {
  1078.                         mapa[i][j] = 2020;
  1079.                     }
  1080.  
  1081.                     if (j == 3 || j == 6)
  1082.                     {
  1083.                         mapa[i][j] = 3125;
  1084.                     }
  1085.  
  1086.                     if (j == 4 || j == 7 || j == 9)
  1087.                     {
  1088.                         mapa[i][j] = 2320;
  1089.                     }
  1090.                 }
  1091.             }
  1092.         }
  1093.         break;
  1094.  
  1095.     case 4: //mapa 4
  1096.         for (int i = 0; i < *fila; i++)
  1097.         {
  1098.             for (int j = 0; j < *columna; j++)
  1099.             {
  1100.                 if (i == 0)
  1101.                 {
  1102.                     mapa[0][0] = 4221; //ENTRADA
  1103.                     mapa[0][1] = 4123;
  1104.                     mapa[0][2] = 5220;
  1105.                     mapa[0][3] = 4320;
  1106.                     mapa[0][5] = 2120;
  1107.                     mapa[0][6] = 3120;
  1108.                     mapa[0][7] = 3125;
  1109.                     mapa[0][8] = 3124;
  1110.                     mapa[0][9] = 2220;
  1111.                 }
  1112.  
  1113.                 if (i == 1)
  1114.                 {
  1115.                     mapa[1][2] = 3025;
  1116.                     mapa[1][3] = 4220;
  1117.                     mapa[1][5] = 2320;
  1118.                     mapa[1][7] = 3125;
  1119.                     mapa[1][8] = 2220;
  1120.  
  1121.                     if (j == 0 || j == 9)
  1122.                     {
  1123.                         mapa[i][j] = 3020;
  1124.                     }
  1125.  
  1126.                     if (j == 4 || j == 6)
  1127.                     {
  1128.                         mapa[i][j] = 2120;
  1129.                     }
  1130.                 }
  1131.  
  1132.                 if (i == 2)
  1133.                 {
  1134.                     mapa[2][8] = 4022; //SALIDA
  1135.                     mapa[2][1] = 4120;
  1136.                     mapa[2][2] = 5020;
  1137.                     mapa[2][3] = 1025;
  1138.                     mapa[2][4] = 2320;
  1139.                     mapa[2][5] = 2125;
  1140.                     mapa[2][6] = 5320;
  1141.  
  1142.                     if (j == 0 || j == 9)
  1143.                     {
  1144.                         mapa[i][j] = 3020;
  1145.                     }
  1146.                 }
  1147.  
  1148.                 if (i == 3)
  1149.                 {
  1150.                     mapa[3][4] = 4120;
  1151.                     mapa[3][5] = 2324;
  1152.  
  1153.                     if (j == 1 || j == 2 || j == 7 || j == 8)
  1154.                     {
  1155.                         mapa[i][j] = 3120;
  1156.                     }
  1157.  
  1158.                     if (j == 0 || j == 6)
  1159.                     {
  1160.                         mapa[i][j] = 2020;
  1161.                     }
  1162.  
  1163.                     if (j == 3 || j == 9)
  1164.                     {
  1165.                         mapa[i][j] = 2320;
  1166.                     }
  1167.                 }
  1168.             }
  1169.         }
  1170.         break;
  1171.  
  1172.     case 5: //mapa 5
  1173.         for (int i = 0; i < *fila; i++)
  1174.         {
  1175.             for (int j = 0; j < *columna; j++)
  1176.             {
  1177.                 if (i == 3)
  1178.                 {
  1179.                     mapa[3][0] = 4121; //ENTRADA
  1180.                     mapa[3][3] = 3124;
  1181.                     mapa[3][5] = 2320;
  1182.                     mapa[3][7] = 2020;
  1183.                     mapa[3][9] = 2320;
  1184.                     mapa[3][8] = 3125;
  1185.  
  1186.                     if (j == 1 || j == 2 || j == 4)
  1187.                     {
  1188.                         mapa[i][j] = 3120;
  1189.                     }
  1190.                 }
  1191.  
  1192.                 if (i == 2)
  1193.                 {
  1194.                     mapa[2][1] = 2320;
  1195.                     mapa[2][4] = 3120;
  1196.                     mapa[2][5] = 1020;
  1197.                     mapa[2][6] = 4324;
  1198.                     mapa[2][7] = 3025;
  1199.                     mapa[2][9] = 4223;
  1200.  
  1201.                     if (j == 0 || j == 3)
  1202.                     {
  1203.                         mapa[i][j] = 2020;
  1204.                     }
  1205.                 }
  1206.  
  1207.                 if (i == 1)
  1208.                 {
  1209.                     mapa[1][0] = 3024;
  1210.                     mapa[1][8] = 2020;
  1211.                     mapa[1][9] = 2320;
  1212.                     mapa[1][2] = 3125;
  1213.                     mapa[1][6] = 3120;
  1214.  
  1215.                     if (j == 1 || j == 5)
  1216.                     {
  1217.                         mapa[i][j] = 2120;
  1218.                     }
  1219.  
  1220.                     if (j == 3 || j == 7)
  1221.                     {
  1222.                         mapa[i][j] = 2220;
  1223.                     }
  1224.                 }
  1225.  
  1226.                 if (i == 0)
  1227.                 {
  1228.                     mapa[0][9] = 4222; //SALIDA
  1229.                     mapa[0][0] = 2120;
  1230.                     mapa[0][8] = 2225;
  1231.  
  1232.                     if (j == 1 || j == 3 || j == 4 || j == 6 || j == 7)
  1233.                     {
  1234.                         mapa[i][j] = 3120;
  1235.                     }
  1236.                     if (j == 2 || j == 5)
  1237.                         mapa[i][j] = 3125;
  1238.                 }
  1239.             }
  1240.         }
  1241.         break;
  1242.     case 6: // mapa 6
  1243.         for (int i = 0; i < *fila; i++)
  1244.         {
  1245.             for (int j = 0; j < *columna; j++)
  1246.             {
  1247.                 if (i == 0)
  1248.                 {
  1249.                     mapa[0][0] = 4121; //entrada
  1250.                     mapa[0][4] = 4224; //tesoro
  1251.                     mapa[0][5] = 2120;
  1252.                     mapa[0][9] = 4222; //salida
  1253.                     mapa[0][1] = 5220;
  1254.                     mapa[0][7] = 5225;
  1255.  
  1256.                     if (j == 2 || j == 6)
  1257.                     {
  1258.                         mapa[i][j] = 3120;
  1259.                     }
  1260.  
  1261.                     if (j == 3 || j == 8)
  1262.                     {
  1263.                         mapa[i][j] = 2225;
  1264.                     }
  1265.                 }
  1266.  
  1267.                 if (i == 1)
  1268.                 {
  1269.                     mapa[1][0] = 2120;
  1270.                     mapa[1][1] = 2320;
  1271.                     mapa[1][2] = 4120;
  1272.                     mapa[1][3] = 1020;
  1273.                     mapa[1][4] = 5320;
  1274.                     mapa[1][7] = 3024; //tesoro
  1275.                     mapa[1][8] = 4023; //llave
  1276.  
  1277.                     if (j == 5 || j == 9)
  1278.                     {
  1279.                         mapa[i][j] = 3020;
  1280.                     }
  1281.                 }
  1282.  
  1283.                 if (i == 2)
  1284.                 {
  1285.                     mapa[2][0] = 3020;
  1286.                     mapa[2][4] = 5120;
  1287.                     mapa[2][5] = 5020;
  1288.                     mapa[2][9] = 5320;
  1289.  
  1290.                     if (j == 1 || j == 8)
  1291.                     {
  1292.                         mapa[i][j] = 2120;
  1293.                     }
  1294.  
  1295.                     if (j == 2 || j == 6)
  1296.                     {
  1297.                         mapa[i][j] = 3125;
  1298.                     }
  1299.  
  1300.                     if (j == 3 || j == 7)
  1301.                     {
  1302.                         mapa[i][j] = 2320;
  1303.                     }
  1304.                 }
  1305.  
  1306.                 if (i == 3)
  1307.                 {
  1308.                     mapa[3][1] = 2020;
  1309.                     mapa[3][2] = 4324; //tesoro
  1310.                     mapa[3][3] = 4120;
  1311.                     mapa[3][4] = 5020;
  1312.                     mapa[3][8] = 2325;
  1313.  
  1314.                     if (j == 0 || j == 9)
  1315.                     {
  1316.                         mapa[i][j] = 4020;
  1317.                     }
  1318.  
  1319.                     if (j == 5 || j == 6 || j == 7)
  1320.                     {
  1321.                         mapa[i][j] = 3120;
  1322.                     }
  1323.                 }
  1324.             }
  1325.         }
  1326.         break;
  1327.     case 7: //mapa 7
  1328.         for (int i = 0; i < *fila; i++)
  1329.         {
  1330.             for (int j = 0; j < *columna; j++)
  1331.             {
  1332.                 if (i == 3)
  1333.                 {
  1334.                     mapa[3][0] = 4021; //ENTRADA
  1335.                     mapa[3][1] = 4124;
  1336.                     mapa[3][2] = 5025;
  1337.                     mapa[3][3] = 4324;
  1338.                     mapa[3][5] = 3120;
  1339.                     mapa[3][6] = 2320;
  1340.                     mapa[3][8] = 3124;
  1341.                     mapa[3][9] = 4323;
  1342.  
  1343.                     if (j == 4 || j == 7)
  1344.                     {
  1345.                         mapa[i][j] = 2025;
  1346.                     }
  1347.                 }
  1348.  
  1349.                 if (i == 2)
  1350.                 {
  1351.                     mapa[2][2] = 1020;
  1352.                     mapa[2][6] = 2120;
  1353.                     mapa[2][7] = 2220;
  1354.                     mapa[2][9] = 2320;
  1355.                     mapa[2][3] = 2325;
  1356.  
  1357.                     if (j == 0 || j == 4)
  1358.                     {
  1359.                         mapa[i][j] = 3020;
  1360.                     }
  1361.  
  1362.                     if (j == 1 || j == 8)
  1363.                     {
  1364.                         mapa[i][j] = 2020;
  1365.                     }
  1366.                 }
  1367.  
  1368.                 if (i == 1)
  1369.                 {
  1370.                     mapa[1][3] = 2120;
  1371.                     mapa[1][4] = 2224;
  1372.                     mapa[1][5] = 2020;
  1373.                     mapa[1][8] = 5325;
  1374.  
  1375.                     if (j == 0 || j == 1 || j == 2 || j == 9)
  1376.                     {
  1377.                         mapa[i][j] = 3020;
  1378.                     }
  1379.  
  1380.                     if (j == 6 || j == 7)
  1381.                     {
  1382.                         mapa[i][j] = 3120;
  1383.                     }
  1384.                 }
  1385.  
  1386.                 if (i == 0)
  1387.                 {
  1388.                     mapa[0][9] = 4222; //SALIDA
  1389.                     mapa[0][6] = 4124;
  1390.                     mapa[0][7] = 3124;
  1391.                     mapa[0][8] = 2225;
  1392.  
  1393.                     if (j == 3 || j == 4)
  1394.                     {
  1395.                         mapa[i][j] = 3120;
  1396.                     }
  1397.  
  1398.                     if (j == 0 || j == 2)
  1399.                     {
  1400.                         mapa[i][j] = 2120;
  1401.                     }
  1402.  
  1403.                     if (j == 1 || j == 5)
  1404.                     {
  1405.                         mapa[i][j] = 2220;
  1406.                     }
  1407.                 }
  1408.             }
  1409.         }
  1410.         break;
  1411.     case 8: // mapa 8 (final)
  1412.         for (int i = 0; i < *fila; i++)
  1413.         {
  1414.             for (int j = 0; j < *columna; j++)
  1415.             {
  1416.                 if (j > 0 && j < 9)
  1417.                     mapa[i][j] = 3120;
  1418.                 if (j == 0)
  1419.                 {
  1420.                     mapa[0][j] = 4122; // SALIDA
  1421.                     mapa[1][j] = 2120;
  1422.                     mapa[2][j] = 2024;
  1423.                     mapa[3][j] = 4121;
  1424.                 }
  1425.                 if (j == 9)
  1426.                 {
  1427.                     if (i == 0 || i == 2)
  1428.                         mapa[i][j] = 2220;
  1429.                     else
  1430.                         mapa[i][j] = 2324;
  1431.                 }
  1432.             }
  1433.         }
  1434.         mapa[0][2] += 5;
  1435.         mapa[0][4] += 5;
  1436.         mapa[0][5] += 5;
  1437.         mapa[0][7] += 5;
  1438.         mapa[1][2] += 5;
  1439.         mapa[1][4] += 5;
  1440.         mapa[1][7] += 5;
  1441.         mapa[2][2] += 5;
  1442.         mapa[2][7] += 5;
  1443.         mapa[3][1] += 3;
  1444.         mapa[3][4] += 5;
  1445.         break;
  1446.     }
  1447. }
  1448.  
  1449. void RotarPieza(int **pieza, int *dir)
  1450. {
  1451.     int dim = 5;
  1452.     int **aux = CrearMatriz(&dim, &dim); // copiar pieza a aux
  1453.     for (int i = 0; i < dim; i++)
  1454.     {
  1455.         for (int j = 0; j < dim; j++)
  1456.         {
  1457.             aux[i][j] = pieza[i][j];
  1458.         }
  1459.     }
  1460.  
  1461.     int counter = (*dir % 1000) / 100; // decomposicion 2do digito
  1462.  
  1463.     for (int a = 0; a < counter; a++)
  1464.     {
  1465.         for (int i = 0; i < dim; i++)
  1466.         {
  1467.             aux[i][4] = pieza[0][i];
  1468.             aux[i][3] = pieza[1][i];
  1469.             aux[i][2] = pieza[2][i];
  1470.             aux[i][1] = pieza[3][i];
  1471.             aux[i][0] = pieza[4][i];
  1472.  
  1473.  
  1474.         }
  1475.         for (int i = 0; i < dim; i++)
  1476.         {
  1477.             for (int j = 0; j < dim; j++)
  1478.                 pieza[i][j] = aux[i][j];
  1479.         }
  1480.  
  1481.     }
  1482.     delete[] aux;
  1483. }
  1484.  
  1485. void BorrarPersonaje(int *i, int *j, int **display)
  1486. {
  1487.     switch (display[*i][*j])
  1488.     {
  1489.  
  1490.     default:
  1491.         cout << (char)176;
  1492.         break;
  1493.     case 1:
  1494.         cout << (char)219;
  1495.         break;
  1496.     case 3:
  1497.         Console::ForegroundColor = ConsoleColor::DarkRed;
  1498.         cout << (char)219;
  1499.         break;
  1500.     case 4:
  1501.         Console::ForegroundColor = ConsoleColor::DarkRed;
  1502.         cout << (char)176;
  1503. break;
  1504.     case 5:
  1505.         Console::ForegroundColor = ConsoleColor::Cyan;
  1506.         cout << (char)254;
  1507.         break;
  1508.     case 8:
  1509.         Console::ForegroundColor = ConsoleColor::Green;
  1510.         cout << 'S';
  1511.         break;
  1512.     case 9:
  1513.         Console::ForegroundColor = ConsoleColor::Red;
  1514.         cout << 'E';
  1515.         break;
  1516.     }
  1517.     Console::ForegroundColor = ConsoleColor::Gray;
  1518. }
  1519.  
  1520. void MoverPersonaje(int *pos_i, int *pos_j, int *dir, int **display)
  1521. {
  1522.     Console::SetCursorPosition(*pos_j + 1, *pos_i + 3);
  1523.     BorrarPersonaje(pos_i, pos_j, display);
  1524.     switch (*dir)
  1525.     {
  1526.     case 1: // arriba
  1527.         if (display[*pos_i - 2][*pos_j] != 1)
  1528.             *pos_i -= 5;
  1529.         break;
  1530.     case 2: // derecha
  1531.         if (display[*pos_i][*pos_j + 2] != 1)
  1532.             *pos_j += 5;
  1533.         break;
  1534.     case 3: // abajo
  1535.         if (display[*pos_i + 2][*pos_j] != 1)
  1536.             *pos_i += 5;
  1537.         break;
  1538.     case 4: // izquierda
  1539.         if (display[*pos_i][*pos_j - 2] != 1)
  1540.             *pos_j -= 5;
  1541.         break;
  1542.     }
  1543.     Console::SetCursorPosition(*pos_j + 1, *pos_i + 3);
  1544.     Console::ForegroundColor = ConsoleColor::Cyan;
  1545.     cout << (char)254;
  1546.     Console::ForegroundColor = ConsoleColor::Gray;
  1547.     *dir = 0;
  1548. }
  1549.  
  1550. void InteractuarConPersonaje(int **display, int *pos_i, int *pos_j, int *to_draw, int *nivel, bool *tiene_llave, int *cant_pociones, int *dmg, int *id_enemigo, int *hp_enemigo, int *ataque, bool *ouch, int *hp_jugador, bool *game_over)
  1551. {
  1552.     switch (display[*pos_i][*pos_j])
  1553.     {
  1554.     case 6:
  1555.         *tiene_llave = true;
  1556.         *to_draw += 100;
  1557.         display[*pos_i][*pos_j] = 2;
  1558.         break;
  1559.     case 7:
  1560.         if (NumeroAleatorio(0, 10) <= 3)
  1561.             *dmg += 1;
  1562.         else
  1563.             *cant_pociones += 1;
  1564.         display[*pos_i][*pos_j] = 2;
  1565.         *to_draw += 100;
  1566.         break;
  1567.     case 8:
  1568.         if (*tiene_llave)
  1569.         {
  1570.             *to_draw = 1111;
  1571.             *nivel += 1;
  1572.             if (*nivel > 8)
  1573.                 *game_over = true;
  1574.             *tiene_llave = false;
  1575.         }
  1576.         break;
  1577.     case 10:
  1578.         *id_enemigo = NumeroAleatorio(1, 9);
  1579.         *to_draw = 10;
  1580.         Texto(id_enemigo, hp_enemigo, dmg, ouch, ataque);
  1581.         *ataque = *dmg + NumeroAleatorio(2, 12);
  1582.         if (*ataque < *hp_enemigo)
  1583.         {
  1584.             *ouch = true;
  1585.             *hp_jugador -= 1;
  1586.             *to_draw += 100;
  1587.         }
  1588.         display[*pos_i][*pos_j] = 2;
  1589.         break;
  1590.     default:
  1591.         break;
  1592.     }
  1593. }
  1594.  
  1595. int NumeroAleatorio(int de, int hasta)
  1596. {
  1597.     return rand() % (hasta - de + 1) + de;
  1598. }
  1599.  
  1600. void Ganaste()
  1601. {
  1602.     Console::ForegroundColor = ConsoleColor::Green;
  1603.     for (int i = 0; i < 1900; i++)
  1604.     {
  1605.         Console::SetCursorPosition(NumeroAleatorio(0, 79), NumeroAleatorio(0, 23));
  1606.         cout << (char)NumeroAleatorio(33, 255);
  1607.         _sleep(1);
  1608.     }
  1609.     for (int i = 0; i < 24; i++)
  1610.     {
  1611.         for (int j = 0; j < 80; j++)
  1612.         {
  1613.             Console::SetCursorPosition(j, i);
  1614.             Console::BackgroundColor = ConsoleColor::Blue;
  1615.             Console::ForegroundColor = ConsoleColor::White;
  1616.             cout << ' ';
  1617.         }
  1618.     }
  1619.  
  1620.     for (int i = 0; i < 24; i++)
  1621.     {
  1622.         for (int j= 0; j < 80; j++)
  1623.         {
  1624.             Console::SetCursorPosition(j, i);
  1625.             Console::BackgroundColor = ConsoleColor::Blue;
  1626.             Console::ForegroundColor = ConsoleColor::Gray;
  1627.  
  1628.             if (i == 6 && j == 21)
  1629.             {
  1630.                 Console::BackgroundColor = ConsoleColor::Gray;
  1631.                 Console::ForegroundColor = ConsoleColor::Blue;
  1632.                 cout << " ...QUE DIABLOS?! ";
  1633.             }
  1634.             else if (i == 8 && j == 14)
  1635.                 cout << "Un error fatal ha ocurrido.";
  1636.             else if (i == 9 && j == 14)
  1637.                 cout << "Aqui tienes un par de numeros aleatorios: 0x732f131 0x523a7e2";
  1638.             else if (i == 10 && j == 14)
  1639.                 cout << "Ganaste, borraste el sistema ... bien hecho.";
  1640.             else if (i == 11 && j == 14)
  1641.                 cout << "Todo lo que no guardaste se perdera.";
  1642.             else if (i == 21 && j == 14)
  1643.                 cout << "Pulsa cualquier tecla para no cambiar nada en absoluto... ";
  1644.         }
  1645.     }
  1646.     _getch();
  1647. }
  1648.  
  1649. void Perdiste()
  1650. {
  1651.     for (int i = 0; i < 24; i++)
  1652.     {
  1653.         for (int j = 0; j < 80; j++)
  1654.         {
  1655.             Console::SetCursorPosition(j, i);
  1656.             Console::BackgroundColor = ConsoleColor::DarkRed;
  1657.             Console::ForegroundColor = ConsoleColor::Gray;
  1658.             cout << ' ';
  1659.         }
  1660.     }
  1661.  
  1662.     for (int i = 0; i < 24; i++)
  1663.     {
  1664.         for (int j = 0; j < 80; j++)
  1665.         {
  1666.             Console::SetCursorPosition(j, i);
  1667.             Console::BackgroundColor = ConsoleColor::DarkRed;
  1668.             Console::ForegroundColor = ConsoleColor::Gray;
  1669.  
  1670.             if (i == 6 && j == 21)
  1671.             {
  1672.                 Console::BackgroundColor = ConsoleColor::Gray;
  1673.                 Console::ForegroundColor = ConsoleColor::DarkRed;
  1674.                 cout << " Aviso importante del ANTIVIRUS: ";
  1675.             }
  1676.             else if (i == 8 && j == 14)
  1677.                 cout << "Encontre un virus en 0x732f131 !";
  1678.             else if (i == 9 && j == 14)
  1679.                 cout << "Lo borre ya que queria corromper el sistema.";
  1680.             else if (i == 10 && j == 14)
  1681.                 cout << "No necesitas agradecermelo. Total, es solo un juego.";
  1682.             else if (i == 21 && j == 14)
  1683.                 cout << "Perdiste. Pulsa cualquier tecla para ser derrotado...";
  1684.         }
  1685.     }
  1686.     _getch();
  1687. }
  1688.  
  1689. int main()
  1690. {
  1691.     bool *es_enter, *es_esc, *tiene_llave, *uso_pocion, *game_over, *ouch;
  1692.     int *scancode, *menu_state, *game_state, *hp_jugador, *cant_pociones,
  1693.         *dmg, *id_enemigo, *hp_enemigo, *fila, *columna, **display,
  1694.         *fila_mapa, *columna_mapa, **mapa, *nivel, *dir, *pos_i, *pos_j, *to_draw,
  1695.         *ataque;
  1696.  
  1697.     scancode = new int; // es el scancode de las teclas ingresadas
  1698.     menu_state = new int; // que opcion se selecciono en el menu
  1699.     es_enter = new bool; // si se presiono enter
  1700.     es_esc = new bool; // si se presiono esc
  1701.     game_state = new int; // que pantalla (menu, juego o ayuda) se esta mostrando
  1702.     tiene_llave = new bool; // si tiene la llave
  1703.     uso_pocion = new bool; // si uso una pocion
  1704.     cant_pociones = new int; // cantidad de pociones que tiene
  1705.     hp_jugador = new int; // la vida del jugador (0-5)
  1706.     dmg = new int; // el danio del jugador
  1707.     ataque = new int; *ataque = 0; // ataque del jugador
  1708.     ouch = new bool; *ouch = false; // determina si el jugador sufre danio
  1709.     game_over = new bool; *game_over = false;
  1710.     id_enemigo = new int; // la identificacion del enemigo
  1711.     hp_enemigo = new int; *hp_enemigo = 0;// la vida del enemigo
  1712.     fila = new int; *fila = 20; // para fichas de 5x5
  1713.     columna = new int; *columna = 50; // para fichas de 5x5
  1714.     fila_mapa = new int; *fila_mapa = *fila / 5;
  1715.     columna_mapa = new int; *columna_mapa = *columna / 5;
  1716.     nivel = new int; *nivel = 1; // el mapa que se va a imprimir
  1717.     dir = new int; // direccion de movimiento del personaje
  1718.     pos_i = new int; *pos_i = 2;
  1719.     pos_j = new int; *pos_j = 2;
  1720.     to_draw = new int; *to_draw = 1111;
  1721.     /*indica que parte de la pantalla del juego tiene que re-dibujar, para que no parpadee toda la pantalla
  1722.     0000 nada
  1723.     1000 mapa & marco
  1724.     0100 status (hp, nivel, etc.)
  1725.     0010 texto
  1726.     0001 personaje
  1727.     */
  1728.  
  1729.     Console::CursorVisible = false;
  1730.  
  1731.     *es_enter = false;
  1732.     *es_esc = false;
  1733.     *menu_state = 0;
  1734.     *game_state = 0;
  1735.     *hp_jugador = 5;
  1736.     *cant_pociones = 0;
  1737.     *dmg = 0;
  1738.     *tiene_llave = false;
  1739.     *uso_pocion = false;
  1740.     *id_enemigo = 0;
  1741.  
  1742.     MenuPrincipal(menu_state, game_state);
  1743.  
  1744.     display = CrearMatriz(fila, columna); // la matriz que sa va a imprimir
  1745.     mapa = CrearMatriz(fila_mapa, columna_mapa);
  1746.     srand(time_t());
  1747.  
  1748.     while (*hp_jugador != 0 && !*game_over)
  1749.     {
  1750.        
  1751.             if (_kbhit() != 0 && *game_state == 1)
  1752.                 Captura(menu_state, es_enter, scancode, es_esc, game_state, uso_pocion, id_enemigo, nivel, dir, to_draw, dmg, hp_jugador, game_over);
  1753.             else if (*game_state != 1)
  1754.                 Captura(menu_state, es_enter, scancode, es_esc, game_state, uso_pocion, id_enemigo, nivel, dir, to_draw, dmg, hp_jugador, game_over);
  1755.  
  1756.         switch (*game_state)
  1757.         {
  1758.         case 0:
  1759.             MenuPrincipal(menu_state, game_state);
  1760.             *to_draw = 1111;
  1761.             break;
  1762.         case 1:
  1763.             if (*to_draw / 1000 == 1)
  1764.             {
  1765.                 GenerarMapa(mapa, fila_mapa, columna_mapa, nivel);
  1766.                 GenerarMatriz(display, mapa, fila_mapa, columna_mapa);
  1767.                 Dibujante(game_state, hp_jugador, cant_pociones, dmg, tiene_llave, uso_pocion, id_enemigo, hp_enemigo, display, fila, columna, nivel, pos_i, pos_j);
  1768.             }
  1769.             if ((*to_draw % 1000) >= 100)
  1770.                 Estado(hp_jugador, cant_pociones, dmg, tiene_llave, uso_pocion);
  1771.             if ((*to_draw % 100) >= 10)
  1772.                 Texto(id_enemigo, hp_enemigo, dmg, ouch, ataque);
  1773.             if ((*to_draw % 10) == 1)
  1774.                 MoverPersonaje(pos_i, pos_j, dir, display);
  1775.             if (*to_draw != 0)
  1776.                 *to_draw = 0;
  1777.             InteractuarConPersonaje(display, pos_i, pos_j, to_draw, nivel, tiene_llave, cant_pociones, dmg, id_enemigo, hp_enemigo, ataque, ouch, hp_jugador, game_over);
  1778.             break;
  1779.         case 2:
  1780.             PantallaAyuda(game_state);
  1781.             break;
  1782.         case 3:
  1783.             delete[] display, mapa;
  1784.  
  1785.             delete es_enter, es_esc, tiene_llave, uso_pocion, game_over,
  1786.                 ouch, scancode, menu_state, game_state, hp_jugador, cant_pociones,
  1787.                 dmg, id_enemigo, hp_enemigo, fila, columna, fila_mapa, columna_mapa,
  1788.                 nivel, dir, pos_i, pos_j, to_draw, ataque;
  1789.             exit(0); // cierra el programa con codigo 0 (return 0)
  1790.             break;
  1791.         }
  1792.     }
  1793.     if (*hp_jugador < 1)
  1794.         Perdiste();
  1795.     else
  1796.         Ganaste();
  1797.  
  1798.     delete[] display, mapa;
  1799.  
  1800.     delete es_enter, es_esc, tiene_llave, uso_pocion, game_over,
  1801.         ouch, scancode, menu_state, game_state, hp_jugador, cant_pociones,
  1802.         dmg, id_enemigo, hp_enemigo, fila, columna, fila_mapa, columna_mapa,
  1803.         nivel, dir, pos_i, pos_j, to_draw, ataque;
  1804.  
  1805.     return 0;
  1806. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement