Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <conio.h>
- #include <stdio.h>
- #include <iostream>
- #include <stdlib.h>
- #include <time.h>
- using namespace System;
- using namespace std;
- #define KEY_UP 72 // estos son los scancodes de las teclas direccionales, las uso en la funcion Captura()
- #define KEY_DOWN 80
- #define KEY_LEFT 75
- #define KEY_RIGHT 77
- // estas son las declaraciones de las funciones. es bueno para ver todas de un vistazo.
- 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);
- //dibuja la pantalla del juego, llama la funcion ImprimirMatriz()
- void Estado(int *hp_jugador, int *cant_pociones, int *dmg, bool *tiene_llave, bool *uso_pocion);
- // dibuja el estado del jugador (HP, pociones, etc)
- void Texto(int *id_enemigo, int *hp_enemigo, int *dmg, bool *ouch, int *ataque);
- // dibuja el texto (lo que sucede cada turno), llama la funcion ImprimirEnemigo()
- void MenuPrincipal(int *menu_state, int *game_screen);
- // dibuja el menu principal
- 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);
- // captura las teclas presionadas
- void PantallaAyuda(int *game_screen);
- // dibuja el menu de ayuda
- void ImprimirEnemigo(int *id_enemigo, int *hp_enemigo);
- // imprime el tipo de enemigo y el hp, segun el valor de *id_enemigo
- void GenerarMatriz(int **display, int **mapa, int *fila, int *columna);
- // le asigna valores a una matriz
- int** CrearMatriz(int *fila, int *columna);
- // crea una matriz del tamano *fila x *columna
- void ImprimirMatriz(int **display, int *fila, int *columna);
- // imprime la matriz **display
- int** GenerarPieza(int *id_pieza);
- // crea y genera una matriz de 5 x 5 segun mapa[][] (*id_pieza)
- void GenerarMapa(int **mapa, int *fila, int *columna, int *nivel);
- // genera una matriz con los valores *id_pieza (las dimensiones de la matriz dada tienen que ser de (*fila / 5) x (*columna / 5)
- void RotarPieza(int **pieza, int *dir);
- /* rota la pieza
- *dir | grados
- 0 0
- 1 90
- 2 180
- 3 270 */
- void ArmarDisplay(int i, int j, int **pieza, int **display);
- // "arma" el display con cada pieza segun el mapa
- 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);
- // lee e interactua con el personaje segun la casilla donde cae
- int NumeroAleatorio(int de, int hasta);
- // genera un int aleatorio en un rango establecio por "de" y "hasta"
- void Ganaste();
- // winscreen
- void Perdiste();
- // killscreen
- // aqui comienzan las funciones
- 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)
- {
- char lo = 201;
- char hori = 205;
- char ro = 187;
- char verti = 186;
- char ru = 188;
- char lu = 200;
- char oT = 203;
- char uT = 202;
- char lT = 204;
- char rT = 185;
- char space = 255;
- bool sigue = true;
- Console::Clear();
- ImprimirMatriz(matriz, fila, columna);
- for (int i = 0; i < *fila && sigue; i++)
- {
- for (int j = 0; j < *columna && sigue; j++)
- {
- if ((matriz[i][j] % 10) == 9)
- {
- *pos_i = i;
- *pos_j = j;
- sigue = false;
- }
- }
- }
- for (int i = 0; i < 24; i++)
- {
- for (int j = 0; j < 51; j++)
- {
- Console::SetCursorPosition(j, i);
- if (j == 0)
- {
- if (i == 0)
- cout << lo;
- else if (i == 2)
- cout << lT;
- else if (i == 23)
- cout << lu;
- else
- cout << verti;
- }
- if (j > 0)
- {
- if (i == 0 || i == 2 || i == 23)
- cout << hori;
- }
- if (j == 2 && i == 1)
- {
- cout << "Nivel: ";
- if (*nivel != 0)
- cout << *nivel;
- else
- {
- Console::ForegroundColor = ConsoleColor::DarkGreen;
- cout << "Debug";
- Console::ForegroundColor = ConsoleColor::Gray;
- }
- }
- }
- }
- for (int j = 0; j < 24; j++) // fila de 1 a 24
- {
- for (int i = 0; i < 29; i++) // HUD
- {
- Console::SetCursorPosition(i + 51, j);
- if (j == 0) // linea superior
- {
- if (i == 0)
- cout << oT;
- else if (i == 28)
- cout << ro;
- else
- cout << hori;
- }
- else if (j == 2 && i == 0)
- {
- cout << rT;
- }
- else if (j == 10) // linea del medio
- {
- if (i == 0)
- cout << lT;
- else if (i == 28)
- cout << rT;
- else
- cout << hori;
- }
- else if (j == 23) // linea inferior
- {
- if (i == 0)
- cout << uT;
- else if (i == 28)
- cout << ru;
- else
- cout << hori;
- }
- else if (i == 0 || i == 28)
- cout << verti;
- }
- }
- *menu_state = 1;
- }
- void Estado(int *hp_jugador, int *cant_pociones, int *dmg, bool *tiene_llave, bool *uso_pocion) // Estado del jugador
- {
- char verti = 186;
- char space = 255;
- char block = 219;
- char points = 176;
- if (*uso_pocion)
- {
- if (*hp_jugador < 5 && *cant_pociones > 0)
- {
- *hp_jugador += 1;
- *cant_pociones -= 1;
- }
- *uso_pocion = false;
- }
- for (int j = 0; j < 24; j++)
- {
- for (int i = 0; i < 29; i++)
- {
- Console::SetCursorPosition(i + 51, j);
- if (i == 2 && j == 2) // 2da linea: HP
- {
- cout << "HP: " << *hp_jugador << "/5";
- }
- else if (i == 11 && j == 2)
- {
- Console::ForegroundColor = ConsoleColor::DarkGray;
- for (int z = 0; z < 15 - (*hp_jugador * 3); z++)
- cout << points;
- Console::ForegroundColor = ConsoleColor::DarkRed;
- for (int z = 0; z < *hp_jugador * 3; z++)
- cout << block;
- Console::ForegroundColor = ConsoleColor::Gray;
- }
- else if (i == 2 && j == 4) // 4ta linea: ataque
- {
- cout << "Nivel de Corrupcion: +" << *dmg;
- }
- else if (i == 2 && j == 6) // 6ta linea: pociones
- {
- cout << "Pointers: " << *cant_pociones;
- }
- else if (i == 2 && j == 8) // 8va linea: tiene la llave?
- {
- if (*tiene_llave)
- {
- cout << "Tienes la ";
- Console::ForegroundColor = ConsoleColor::Yellow;
- cout << "LLAVE";
- Console::ForegroundColor = ConsoleColor::Gray;
- cout << "! ";
- }
- else
- {
- cout << "No tienes la ";
- Console::ForegroundColor = ConsoleColor::Yellow;
- cout << "LLAVE";
- Console::ForegroundColor = ConsoleColor::Gray;
- }
- }
- }
- }
- }
- void Texto(int *id_enemigo, int *hp_enemigo, int *dmg, bool *ouch, int *ataque)
- {
- for (int j = 0; j < 24; j++)
- {
- for (int i = 0; i < 29; i++)
- {
- Console::SetCursorPosition(i + 51, j);
- if (j == 12 && i == 2)
- {
- cout << "Te ataca";
- }
- else if (j == 13 && i == 2)
- {
- ImprimirEnemigo(id_enemigo, hp_enemigo);
- }
- else if (j == 14 && i == 5)
- {
- cout << "con ";
- if (*hp_enemigo < 10)
- cout << '0';
- cout << *hp_enemigo << " HP! ";
- }
- else if (j == 16 && i == 2)
- {
- cout << "Tu atacas con ";
- if (*ataque < 10)
- cout << '0';
- cout << *ataque << " !";
- }
- else if (j == 18 && i == 2)
- {
- ImprimirEnemigo(id_enemigo, hp_enemigo);
- }
- else if (j == 19 && i == 5)
- {
- if (*ouch)
- {
- cout << "explota y te quita 1HP!";
- *ouch = false;
- }
- else
- {
- cout << "explota! ";
- }
- }
- }
- }
- }
- void ImprimirEnemigo(int *id_enemigo, int *hp_enemigo)
- {
- switch (*id_enemigo)
- {
- case 9:
- cout << "int ";
- *hp_enemigo = 5;
- break;
- case 1:
- cout << "double ";
- *hp_enemigo = 6;
- break;
- case 2:
- cout << "string ";
- *hp_enemigo = 8;
- break;
- case 3:
- cout << "function() ";
- *hp_enemigo = 7;
- break;
- case 4:
- cout << "class ";
- *hp_enemigo = 10;
- break;
- case 5:
- cout << "library ";
- *hp_enemigo = 13;
- break;
- case 6:
- cout << "cmd.exe ";
- *hp_enemigo = 12;
- break;
- case 7:
- cout << "rootmdm.sys ";
- *hp_enemigo = 12;
- break;
- case 8:
- cout << "system32 ";
- *hp_enemigo = 15;
- break;
- }
- }
- void MenuPrincipal(int *menu_state, int *game_screen)
- {
- Console::Clear();
- for (int j = 0; j < 16; j++)
- {
- Console::SetCursorPosition(25, j + 2);
- switch (j)
- {
- case 0:
- cout << " _____ _____ _____ _____ _____ ";
- break;
- case 1:
- cout << "| _ | __| | | |";
- break;
- case 2:
- cout << "| |__ | --|- -|- -|";
- break;
- case 3:
- cout << "|__|__|_____|_____|_____|_____|";
- break;
- case 4:
- Console::ForegroundColor = ConsoleColor::DarkRed;
- cout << " _ ";
- break;
- case 5:
- cout << " _| |_ _ ___ ___ ___ ___ ___ ";
- break;
- case 6:
- cout << " | . | | | | . | -_| . | |";
- break;
- case 7:
- cout << " |___|___|_|_|_ |___|___|_|_|";
- break;
- case 8:
- cout << " |___| ";
- Console::ForegroundColor = ConsoleColor::Gray;
- break;
- case 11:
- if (*menu_state == 0)
- {
- Console::BackgroundColor = ConsoleColor::DarkRed;
- Console::ForegroundColor = ConsoleColor::Black;
- }
- cout << "[ run hack.bat ]";
- Console::BackgroundColor = ConsoleColor::Black;
- Console::ForegroundColor = ConsoleColor::Gray;
- break;
- case 13:
- if (*menu_state == 1)
- {
- Console::BackgroundColor = ConsoleColor::DarkRed;
- Console::ForegroundColor = ConsoleColor::Black;
- }
- cout << "[ README.txt ]";
- Console::BackgroundColor = ConsoleColor::Black;
- Console::ForegroundColor = ConsoleColor::Gray;
- break;
- case 15:
- if (*menu_state == 2)
- {
- Console::BackgroundColor = ConsoleColor::DarkRed;
- Console::ForegroundColor = ConsoleColor::Black;
- }
- cout << "[ system.shutdown ]";
- Console::BackgroundColor = ConsoleColor::Black;
- Console::ForegroundColor = ConsoleColor::Gray;
- break;
- default:
- break;
- }
- }
- *game_screen = 0;
- }
- void PantallaAyuda(int *game_screen)
- {
- char hori = 205;
- char verti = 186;
- char lo = 201;
- char ro = 187;
- char ru = 188;
- char lu = 200;
- char lT = 204;
- char rT = 185;
- char jugador = 254;
- char llave = 'L';
- char tesoro = 'T';
- char salida = 'S';
- char pared = 219;
- char piso = 176;
- Console::Clear();
- for (int j = 0; j < 24; j++) // fila
- {
- for (int i = 0; i < 80; i++) // columna
- {
- Console::SetCursorPosition(i, j);
- if (j == 0)
- {
- if (i == 0)
- cout << lo;
- else if (i == 79)
- cout << ro;
- else
- cout << hori;
- }
- if (j > 0 && j < 15)
- {
- if (i == 0 || i == 79)
- cout << verti;
- else if (i == 4)
- {
- switch (j - 3)
- {
- case 0:
- Console::ForegroundColor = ConsoleColor::Yellow;
- cout << llave;
- break;
- case 2:
- Console::ForegroundColor = ConsoleColor::Magenta;
- cout << tesoro;
- break;
- case 4:
- Console::ForegroundColor = ConsoleColor::Green;
- cout << salida;
- break;
- case 6:
- Console::ForegroundColor = ConsoleColor::Red;
- cout << (char)64;
- break;
- case 8:
- Console::ForegroundColor = ConsoleColor::Gray;
- cout << pared << piso << piso << piso << pared;
- break;
- case 10:
- Console::ForegroundColor = ConsoleColor::Cyan;
- cout << jugador;
- break;
- default:
- break;
- }
- Console::ForegroundColor = ConsoleColor::Gray;
- }
- else if (i == 17)
- {
- switch (j - 3)
- {
- case 0:
- cout << "Llave (nesecitaras esto)";
- break;
- case 2:
- cout << "Tesoro (a.k.a datos desprotegidos)";
- break;
- case 4:
- cout << "Salida del Nivel (esto todavia sigue!?)";
- break;
- case 6:
- cout << "Enemigo (cuidado, antivirus!)";
- break;
- case 8:
- cout << "Memoria (totalmente seguro, confia en mi ...)";
- break;
- case 10:
- cout << "hack.bat (efectivamente, este eres tu)";
- break;
- default:
- break;
- }
- }
- }
- if (j == 15)
- {
- if (i == 0)
- cout << lT;
- else if (i == 79)
- cout << rT;
- else
- cout << hori;
- }
- if (j > 15 && j < 23)
- {
- if (i == 0 || i == 79)
- cout << verti;
- else if (i == 4)
- {
- Console::ForegroundColor = ConsoleColor::White;
- switch (j - 17)
- {
- case 0:
- cout << "Arrow Keys";
- break;
- case 2:
- cout << 'P';
- break;
- case 4:
- cout << "Esc";
- break;
- }
- Console::ForegroundColor = ConsoleColor::Gray;
- }
- else if (i == 17)
- {
- switch (j - 17)
- {
- case 0:
- cout << "para moverse (...duh)";
- break;
- case 2:
- cout << "para acceder a un puntero (si te quedan algunos)";
- break;
- case 4:
- cout << "para salir al Menu Principal (no te culpo si me dejas D,: )";
- break;
- }
- }
- }
- if (j == 23)
- {
- if (i == 0)
- cout << lu;
- else if (i == 79)
- cout << ru;
- else
- cout << hori;
- }
- }
- }
- *game_screen = 2;
- }
- 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)
- {
- switch ((*scancode = _getch()))
- {
- case KEY_UP:
- //cout << endl << "Up" << endl;
- if (*menu != 0 && *status == 0)
- *menu -= 1;
- else if (*status == 0)
- *menu = 2;
- *dir = 1;
- *to_draw += 1;
- break;
- case KEY_DOWN:
- //cout << endl << "Down" << endl;
- if (*menu != 2 && *status == 0)
- *menu += 1;
- else if (*status == 0)
- *menu = 0;
- *dir = 3;
- *to_draw += 1;
- break;
- case KEY_LEFT:
- //cout << endl << "Left" << endl;
- *dir = 4;
- *to_draw += 1;
- break;
- case KEY_RIGHT:
- //cout << endl << "Right" << endl;
- *dir = 2;
- *to_draw += 1;
- break;
- case 13:
- //cout << endl << "Enter" << endl;
- *enter = true;
- *to_draw += 10;
- break;
- case 27:
- *esc = true;
- break;
- case 112: // 'p'
- if (*status == 1)
- {
- *uso_pocion = true;
- *to_draw += 100;
- }
- break;
- case 97: // 'a'
- if (*id_enemigo != 8 && *status == 1)
- *id_enemigo += 1;
- else if (*status == 1)
- *id_enemigo = 0;
- *to_draw += 10;
- break;
- case 111: // 'o'
- *nivel += 1;
- if (*nivel > 8)
- *nivel = 0;
- *to_draw += 1111;
- break;
- case 105: // 'i'
- *dmg += 1;
- *to_draw += 100;
- break;
- case 117: // 'u'
- *hp_jugador -= 1;
- if (*hp_jugador < 0)
- *hp_jugador = 0;
- *to_draw += 100;
- break;
- case 121: // 'y'
- *game_over = true;
- default:
- //cout << endl << *scancode << endl;
- break;
- }
- if (*esc && *status == 1 || *status == 2)
- {
- *status = 0;
- *esc = false;
- }
- if (*status == 0)
- {
- if (*enter && *menu == 0)
- *status = 1;
- if (*enter && *menu == 1)
- *status = 2;
- if (*enter && *menu == 2)
- *status = 3;
- *enter = false;
- }
- }
- int** CrearMatriz(int *fila, int *columna)
- {
- int **auxMatrix = new int *[*fila];
- for (int i = 0; i < *fila; i++)
- {
- auxMatrix[i] = new int[*columna];
- }
- return auxMatrix;
- }
- void GenerarMatriz(int **display, int **mapa, int *fila_mapa, int *columna_mapa) // cambia test por &mapa[i][j]
- {
- int test = 10;
- for (int i = 0; i < *fila_mapa; i++)
- {
- for (int j = 0; j < *columna_mapa; j++)
- {
- int **pieza = GenerarPieza(&mapa[i][j]);
- RotarPieza(pieza, &mapa[i][j]);
- ArmarDisplay(i, j, pieza, display);
- Console::SetCursorPosition(j * 2, i + 24);
- cout << mapa[i][j];
- }
- }
- }
- void ArmarDisplay(int i, int j, int **pieza, int **display)
- {
- int rango_i = i * 5;
- int rango_j = j * 5;
- for (int m = rango_i; m < (rango_i + 5); m++)
- {
- for (int n = rango_j; n < (rango_j + 5); n++)
- {
- display[m][n] = pieza[m % 5][n % 5];
- }
- }
- }
- void ImprimirMatriz(int **matriz, int *fila, int *columna)
- {
- for (int i = 0; i < *fila; i++)
- {
- for (int j = 0; j < *columna; j++)
- {
- Console::SetCursorPosition(j + 1, i + 3);
- /*
- 1 = pared safe
- 2 = piso safe
- 3 = pared danger
- 4 = piso danger
- 5 = jugador
- 6 = llave
- 7 = tesoro
- 8 = salida
- 9 = entrada
- 10 = enemigo
- */
- switch (matriz[i][j])
- {
- case 1:
- cout << (char)219;
- break;
- case 2:
- cout << (char)176;
- break;
- case 3:
- Console::ForegroundColor = ConsoleColor::DarkRed;
- cout << (char)219;
- break;
- case 4:
- Console::ForegroundColor = ConsoleColor::DarkRed;
- cout << (char)176;
- break;
- case 5:
- Console::ForegroundColor = ConsoleColor::Cyan;
- cout << (char)254;
- break;
- case 6:
- Console::ForegroundColor = ConsoleColor::Yellow;
- cout << 'L';
- break;
- case 7:
- Console::ForegroundColor = ConsoleColor::Magenta;
- cout << 'T';
- break;
- case 8:
- Console::ForegroundColor = ConsoleColor::Green;
- cout << 'S';
- break;
- case 9:
- Console::ForegroundColor = ConsoleColor::Red;
- cout << 'E';
- break;
- case 10:
- Console::ForegroundColor = ConsoleColor::Red;
- cout << (char)64;
- }
- Console::ForegroundColor = ConsoleColor::Gray;
- }
- }
- }
- int** GenerarPieza(int *id_pieza)
- {
- /*
- 0 = nada
- 1 = pared safe
- 2 = piso safe
- 3 = pared danger
- 4 = piso danger
- 5 = jugador
- 6 = llave
- 7 = tesoro
- 8 = salida
- 9 = entrada
- 10 = enemigo
- */
- int tipo = *id_pieza / 1000; // decomposicion del primer digito
- int item = *id_pieza % 10; // decomposicion del untimo digito
- int dim = 5;
- int **aux = CrearMatriz(&dim, &dim);
- for (int i = 0; i < 5; i++)
- {
- for (int j = 0; j < 5; j++)
- {
- switch (tipo)
- {
- case 1: // cruz
- if (j == 0 || j == 4)
- {
- if (i == 0 || i == 4)
- aux[i][j] = 1;
- else
- aux[i][j] = 2;
- }
- else
- aux[i][j] = 2;
- break;
- case 2: // L
- if (j == 0)
- aux[i][j] = 1;
- else if (i == 4)
- aux[i][j] = 1;
- else if (i == 0 && j == 4)
- aux[i][j] = 1;
- else
- aux[i][j] = 2;
- break;
- case 3: // recta
- if (j == 0 || j == 4)
- aux[i][j] = 1;
- else
- aux[i][j] = 2;
- break;
- case 4: // callejon
- if (j == 0 || j == 4)
- aux[i][j] = 1;
- else if (i == 4)
- aux[i][j] = 1;
- else
- aux[i][j] = 2;
- break;
- case 5: // T
- if (i == 4)
- aux[i][j] = 1;
- else if (i == 0 && (j == 0 || j == 4))
- aux[i][j] = 1;
- else
- aux[i][j] = 2;
- break;
- case 6: // vacio
- aux[i][j] = 0;
- }
- }
- }
- switch (item)
- {
- case 0:
- break;
- case 1:
- aux[2][2] = 9;
- break;
- case 2:
- aux[2][2] = 8;
- break;
- case 3:
- aux[2][2] = 6;
- break;
- case 4:
- aux[2][2] = 7;
- break;
- case 5:
- aux[2][2] = 10;
- break;
- }
- return aux;
- }
- void GenerarMapa(int **mapa, int *fila, int *columna, int *nivel) // *columna = *columna_mapa, *fila = *fila_mapa
- {
- for (int i = 0; i < *fila; i++)
- {
- for (int j = 0; j < *columna; j++)
- {
- mapa[i][j] = 6000;
- }
- }
- switch (*nivel)
- {
- case 0: // debug
- for (int i = 0; i < *fila; i++)
- {
- for (int j = 0; j < *columna; j++)
- {
- if (i == 0)
- {
- if (j > 0 && j < 9)
- mapa[i][j] = 3120;
- }
- else
- mapa[i][j] = 6000;
- }
- }
- mapa[0][0] = 4121;
- mapa[0][1] += 4;
- mapa[0][9] = 4322;
- mapa[0][3] += 3;
- mapa[0][5] += 5;
- break;
- case 1: // mapa 1 (prologo)
- for (int i = 0; i < *fila; i++)
- {
- for (int j = 0; j < *columna; j++)
- {
- if (i == 0)
- {
- if (j > 2 && j < 7)
- mapa[i][j] = 3120;
- }
- if (j == 2 || j == 7)
- {
- if (i == 1 || i == 2)
- mapa[i][j] = 3020;
- }
- if (j == 1 || j == 8)
- {
- if(i == 3)
- mapa[i][j] = 3120;
- }
- }
- }
- mapa[3][2] = 2325;
- mapa[0][2] = 2124;
- mapa[0][7] = 2225;
- mapa[3][7] = 2023;
- mapa[3][0] = 4121;
- mapa[3][9] = 4322;
- break;
- case 2: //mapa 2
- for (int i = 0; i < *fila; i++)
- {
- for (int j = 0; j < *columna; j++)
- {
- if (i == 3)
- {
- mapa[3][0] = 4121; //ENTRADA
- mapa[3][1] = 5020;
- mapa[3][9] = 2324;
- if (j > 1 && j < 9)
- {
- mapa[i][j] = 3120;
- }
- }
- if (i == 2)
- {
- mapa[2][0] = 4123;
- mapa[2][1] = 2225;
- mapa[2][9] = 3020;
- if (j == 3 || j == 6)
- {
- mapa[i][j] = 3120;
- }
- if (j == 2 || j == 5)
- {
- mapa[i][j] = 2020;
- }
- if (j == 4 || j == 7)
- {
- mapa[i][j] = 2320;
- }
- }
- if (i == 1)
- {
- mapa[1][0] = 2020;
- mapa[1][6] = 4024;
- if (j == 1 || j == 8)
- {
- mapa[i][j] = 3120;
- }
- if (j == 2 || j == 5 || j == 9)
- {
- mapa[i][j] = 2220;
- }
- if (j == 4 || j == 7)
- {
- mapa[i][j] = 2125;
- }
- }
- if (i == 0)
- {
- mapa[0][9] = 4322; //SALIDA
- mapa[0][6] = 5225;
- mapa[0][0] = 2120;
- if (j > 0 && j < 6 || j == 7 || j == 8)
- {
- mapa[i][j] = 3120;
- }
- }
- }
- }
- break;
- case 3: //mapa 3
- for (int i = 0; i < *fila; i++)
- {
- for (int j = 0; j < *columna; j++)
- {
- if (i == 0)
- {
- mapa[0][0] = 2125;
- mapa[0][1] = 3125;
- mapa[0][2] = 4324;
- mapa[0][3] = 4223;
- mapa[0][6] = 4124;
- if (j == 0 || j == 4 || j == 8)
- {
- mapa[i][j] = 2120;
- }
- if (j == 5 || j == 7 || j == 9)
- {
- mapa[i][j] = 2220;
- }
- }
- if (i == 1)
- {
- mapa[1][0] = 2020;
- mapa[1][1] = 2220;
- mapa[1][2] = 2120;
- mapa[1][5] = 5120;
- mapa[1][6] = 3120;
- if (j == 3 || j == 7)
- {
- mapa[i][j] = 2325;
- }
- if (j == 4 || j == 8 || j == 9)
- {
- mapa[i][j] = 3020;
- }
- }
- if (i == 2)
- {
- mapa[2][0] = 4121; //ENTRADA
- mapa[2][1] = 5320;
- mapa[2][7] = 2120;
- mapa[2][8] = 2320;
- mapa[2][9] = 3025;
- if (j == 2 || j == 4 || j == 5)
- {
- mapa[i][j] = 3020;
- }
- }
- if (i == 3)
- {
- mapa[3][8] = 4122; //SALIDA
- mapa[3][2] = 5020;
- if (j == 1 || j == 5)
- {
- mapa[i][j] = 2020;
- }
- if (j == 3 || j == 6)
- {
- mapa[i][j] = 3125;
- }
- if (j == 4 || j == 7 || j == 9)
- {
- mapa[i][j] = 2320;
- }
- }
- }
- }
- break;
- case 4: //mapa 4
- for (int i = 0; i < *fila; i++)
- {
- for (int j = 0; j < *columna; j++)
- {
- if (i == 0)
- {
- mapa[0][0] = 4221; //ENTRADA
- mapa[0][1] = 4123;
- mapa[0][2] = 5220;
- mapa[0][3] = 4320;
- mapa[0][5] = 2120;
- mapa[0][6] = 3120;
- mapa[0][7] = 3125;
- mapa[0][8] = 3124;
- mapa[0][9] = 2220;
- }
- if (i == 1)
- {
- mapa[1][2] = 3025;
- mapa[1][3] = 4220;
- mapa[1][5] = 2320;
- mapa[1][7] = 3125;
- mapa[1][8] = 2220;
- if (j == 0 || j == 9)
- {
- mapa[i][j] = 3020;
- }
- if (j == 4 || j == 6)
- {
- mapa[i][j] = 2120;
- }
- }
- if (i == 2)
- {
- mapa[2][8] = 4022; //SALIDA
- mapa[2][1] = 4120;
- mapa[2][2] = 5020;
- mapa[2][3] = 1025;
- mapa[2][4] = 2320;
- mapa[2][5] = 2125;
- mapa[2][6] = 5320;
- if (j == 0 || j == 9)
- {
- mapa[i][j] = 3020;
- }
- }
- if (i == 3)
- {
- mapa[3][4] = 4120;
- mapa[3][5] = 2324;
- if (j == 1 || j == 2 || j == 7 || j == 8)
- {
- mapa[i][j] = 3120;
- }
- if (j == 0 || j == 6)
- {
- mapa[i][j] = 2020;
- }
- if (j == 3 || j == 9)
- {
- mapa[i][j] = 2320;
- }
- }
- }
- }
- break;
- case 5: //mapa 5
- for (int i = 0; i < *fila; i++)
- {
- for (int j = 0; j < *columna; j++)
- {
- if (i == 3)
- {
- mapa[3][0] = 4121; //ENTRADA
- mapa[3][3] = 3124;
- mapa[3][5] = 2320;
- mapa[3][7] = 2020;
- mapa[3][9] = 2320;
- mapa[3][8] = 3125;
- if (j == 1 || j == 2 || j == 4)
- {
- mapa[i][j] = 3120;
- }
- }
- if (i == 2)
- {
- mapa[2][1] = 2320;
- mapa[2][4] = 3120;
- mapa[2][5] = 1020;
- mapa[2][6] = 4324;
- mapa[2][7] = 3025;
- mapa[2][9] = 4223;
- if (j == 0 || j == 3)
- {
- mapa[i][j] = 2020;
- }
- }
- if (i == 1)
- {
- mapa[1][0] = 3024;
- mapa[1][8] = 2020;
- mapa[1][9] = 2320;
- mapa[1][2] = 3125;
- mapa[1][6] = 3120;
- if (j == 1 || j == 5)
- {
- mapa[i][j] = 2120;
- }
- if (j == 3 || j == 7)
- {
- mapa[i][j] = 2220;
- }
- }
- if (i == 0)
- {
- mapa[0][9] = 4222; //SALIDA
- mapa[0][0] = 2120;
- mapa[0][8] = 2225;
- if (j == 1 || j == 3 || j == 4 || j == 6 || j == 7)
- {
- mapa[i][j] = 3120;
- }
- if (j == 2 || j == 5)
- mapa[i][j] = 3125;
- }
- }
- }
- break;
- case 6: // mapa 6
- for (int i = 0; i < *fila; i++)
- {
- for (int j = 0; j < *columna; j++)
- {
- if (i == 0)
- {
- mapa[0][0] = 4121; //entrada
- mapa[0][4] = 4224; //tesoro
- mapa[0][5] = 2120;
- mapa[0][9] = 4222; //salida
- mapa[0][1] = 5220;
- mapa[0][7] = 5225;
- if (j == 2 || j == 6)
- {
- mapa[i][j] = 3120;
- }
- if (j == 3 || j == 8)
- {
- mapa[i][j] = 2225;
- }
- }
- if (i == 1)
- {
- mapa[1][0] = 2120;
- mapa[1][1] = 2320;
- mapa[1][2] = 4120;
- mapa[1][3] = 1020;
- mapa[1][4] = 5320;
- mapa[1][7] = 3024; //tesoro
- mapa[1][8] = 4023; //llave
- if (j == 5 || j == 9)
- {
- mapa[i][j] = 3020;
- }
- }
- if (i == 2)
- {
- mapa[2][0] = 3020;
- mapa[2][4] = 5120;
- mapa[2][5] = 5020;
- mapa[2][9] = 5320;
- if (j == 1 || j == 8)
- {
- mapa[i][j] = 2120;
- }
- if (j == 2 || j == 6)
- {
- mapa[i][j] = 3125;
- }
- if (j == 3 || j == 7)
- {
- mapa[i][j] = 2320;
- }
- }
- if (i == 3)
- {
- mapa[3][1] = 2020;
- mapa[3][2] = 4324; //tesoro
- mapa[3][3] = 4120;
- mapa[3][4] = 5020;
- mapa[3][8] = 2325;
- if (j == 0 || j == 9)
- {
- mapa[i][j] = 4020;
- }
- if (j == 5 || j == 6 || j == 7)
- {
- mapa[i][j] = 3120;
- }
- }
- }
- }
- break;
- case 7: //mapa 7
- for (int i = 0; i < *fila; i++)
- {
- for (int j = 0; j < *columna; j++)
- {
- if (i == 3)
- {
- mapa[3][0] = 4021; //ENTRADA
- mapa[3][1] = 4124;
- mapa[3][2] = 5025;
- mapa[3][3] = 4324;
- mapa[3][5] = 3120;
- mapa[3][6] = 2320;
- mapa[3][8] = 3124;
- mapa[3][9] = 4323;
- if (j == 4 || j == 7)
- {
- mapa[i][j] = 2025;
- }
- }
- if (i == 2)
- {
- mapa[2][2] = 1020;
- mapa[2][6] = 2120;
- mapa[2][7] = 2220;
- mapa[2][9] = 2320;
- mapa[2][3] = 2325;
- if (j == 0 || j == 4)
- {
- mapa[i][j] = 3020;
- }
- if (j == 1 || j == 8)
- {
- mapa[i][j] = 2020;
- }
- }
- if (i == 1)
- {
- mapa[1][3] = 2120;
- mapa[1][4] = 2224;
- mapa[1][5] = 2020;
- mapa[1][8] = 5325;
- if (j == 0 || j == 1 || j == 2 || j == 9)
- {
- mapa[i][j] = 3020;
- }
- if (j == 6 || j == 7)
- {
- mapa[i][j] = 3120;
- }
- }
- if (i == 0)
- {
- mapa[0][9] = 4222; //SALIDA
- mapa[0][6] = 4124;
- mapa[0][7] = 3124;
- mapa[0][8] = 2225;
- if (j == 3 || j == 4)
- {
- mapa[i][j] = 3120;
- }
- if (j == 0 || j == 2)
- {
- mapa[i][j] = 2120;
- }
- if (j == 1 || j == 5)
- {
- mapa[i][j] = 2220;
- }
- }
- }
- }
- break;
- case 8: // mapa 8 (final)
- for (int i = 0; i < *fila; i++)
- {
- for (int j = 0; j < *columna; j++)
- {
- if (j > 0 && j < 9)
- mapa[i][j] = 3120;
- if (j == 0)
- {
- mapa[0][j] = 4122; // SALIDA
- mapa[1][j] = 2120;
- mapa[2][j] = 2024;
- mapa[3][j] = 4121;
- }
- if (j == 9)
- {
- if (i == 0 || i == 2)
- mapa[i][j] = 2220;
- else
- mapa[i][j] = 2324;
- }
- }
- }
- mapa[0][2] += 5;
- mapa[0][4] += 5;
- mapa[0][5] += 5;
- mapa[0][7] += 5;
- mapa[1][2] += 5;
- mapa[1][4] += 5;
- mapa[1][7] += 5;
- mapa[2][2] += 5;
- mapa[2][7] += 5;
- mapa[3][1] += 3;
- mapa[3][4] += 5;
- break;
- }
- }
- void RotarPieza(int **pieza, int *dir)
- {
- int dim = 5;
- int **aux = CrearMatriz(&dim, &dim); // copiar pieza a aux
- for (int i = 0; i < dim; i++)
- {
- for (int j = 0; j < dim; j++)
- {
- aux[i][j] = pieza[i][j];
- }
- }
- int counter = (*dir % 1000) / 100; // decomposicion 2do digito
- for (int a = 0; a < counter; a++)
- {
- for (int i = 0; i < dim; i++)
- {
- aux[i][4] = pieza[0][i];
- aux[i][3] = pieza[1][i];
- aux[i][2] = pieza[2][i];
- aux[i][1] = pieza[3][i];
- aux[i][0] = pieza[4][i];
- }
- for (int i = 0; i < dim; i++)
- {
- for (int j = 0; j < dim; j++)
- pieza[i][j] = aux[i][j];
- }
- }
- delete[] aux;
- }
- void BorrarPersonaje(int *i, int *j, int **display)
- {
- switch (display[*i][*j])
- {
- default:
- cout << (char)176;
- break;
- case 1:
- cout << (char)219;
- break;
- case 3:
- Console::ForegroundColor = ConsoleColor::DarkRed;
- cout << (char)219;
- break;
- case 4:
- Console::ForegroundColor = ConsoleColor::DarkRed;
- cout << (char)176;
- break;
- case 5:
- Console::ForegroundColor = ConsoleColor::Cyan;
- cout << (char)254;
- break;
- case 8:
- Console::ForegroundColor = ConsoleColor::Green;
- cout << 'S';
- break;
- case 9:
- Console::ForegroundColor = ConsoleColor::Red;
- cout << 'E';
- break;
- }
- Console::ForegroundColor = ConsoleColor::Gray;
- }
- void MoverPersonaje(int *pos_i, int *pos_j, int *dir, int **display)
- {
- Console::SetCursorPosition(*pos_j + 1, *pos_i + 3);
- BorrarPersonaje(pos_i, pos_j, display);
- switch (*dir)
- {
- case 1: // arriba
- if (display[*pos_i - 2][*pos_j] != 1)
- *pos_i -= 5;
- break;
- case 2: // derecha
- if (display[*pos_i][*pos_j + 2] != 1)
- *pos_j += 5;
- break;
- case 3: // abajo
- if (display[*pos_i + 2][*pos_j] != 1)
- *pos_i += 5;
- break;
- case 4: // izquierda
- if (display[*pos_i][*pos_j - 2] != 1)
- *pos_j -= 5;
- break;
- }
- Console::SetCursorPosition(*pos_j + 1, *pos_i + 3);
- Console::ForegroundColor = ConsoleColor::Cyan;
- cout << (char)254;
- Console::ForegroundColor = ConsoleColor::Gray;
- *dir = 0;
- }
- 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)
- {
- switch (display[*pos_i][*pos_j])
- {
- case 6:
- *tiene_llave = true;
- *to_draw += 100;
- display[*pos_i][*pos_j] = 2;
- break;
- case 7:
- if (NumeroAleatorio(0, 10) <= 3)
- *dmg += 1;
- else
- *cant_pociones += 1;
- display[*pos_i][*pos_j] = 2;
- *to_draw += 100;
- break;
- case 8:
- if (*tiene_llave)
- {
- *to_draw = 1111;
- *nivel += 1;
- if (*nivel > 8)
- *game_over = true;
- *tiene_llave = false;
- }
- break;
- case 10:
- *id_enemigo = NumeroAleatorio(1, 9);
- *to_draw = 10;
- Texto(id_enemigo, hp_enemigo, dmg, ouch, ataque);
- *ataque = *dmg + NumeroAleatorio(2, 12);
- if (*ataque < *hp_enemigo)
- {
- *ouch = true;
- *hp_jugador -= 1;
- *to_draw += 100;
- }
- display[*pos_i][*pos_j] = 2;
- break;
- default:
- break;
- }
- }
- int NumeroAleatorio(int de, int hasta)
- {
- return rand() % (hasta - de + 1) + de;
- }
- void Ganaste()
- {
- Console::ForegroundColor = ConsoleColor::Green;
- for (int i = 0; i < 1900; i++)
- {
- Console::SetCursorPosition(NumeroAleatorio(0, 79), NumeroAleatorio(0, 23));
- cout << (char)NumeroAleatorio(33, 255);
- _sleep(1);
- }
- for (int i = 0; i < 24; i++)
- {
- for (int j = 0; j < 80; j++)
- {
- Console::SetCursorPosition(j, i);
- Console::BackgroundColor = ConsoleColor::Blue;
- Console::ForegroundColor = ConsoleColor::White;
- cout << ' ';
- }
- }
- for (int i = 0; i < 24; i++)
- {
- for (int j= 0; j < 80; j++)
- {
- Console::SetCursorPosition(j, i);
- Console::BackgroundColor = ConsoleColor::Blue;
- Console::ForegroundColor = ConsoleColor::Gray;
- if (i == 6 && j == 21)
- {
- Console::BackgroundColor = ConsoleColor::Gray;
- Console::ForegroundColor = ConsoleColor::Blue;
- cout << " ...QUE DIABLOS?! ";
- }
- else if (i == 8 && j == 14)
- cout << "Un error fatal ha ocurrido.";
- else if (i == 9 && j == 14)
- cout << "Aqui tienes un par de numeros aleatorios: 0x732f131 0x523a7e2";
- else if (i == 10 && j == 14)
- cout << "Ganaste, borraste el sistema ... bien hecho.";
- else if (i == 11 && j == 14)
- cout << "Todo lo que no guardaste se perdera.";
- else if (i == 21 && j == 14)
- cout << "Pulsa cualquier tecla para no cambiar nada en absoluto... ";
- }
- }
- _getch();
- }
- void Perdiste()
- {
- for (int i = 0; i < 24; i++)
- {
- for (int j = 0; j < 80; j++)
- {
- Console::SetCursorPosition(j, i);
- Console::BackgroundColor = ConsoleColor::DarkRed;
- Console::ForegroundColor = ConsoleColor::Gray;
- cout << ' ';
- }
- }
- for (int i = 0; i < 24; i++)
- {
- for (int j = 0; j < 80; j++)
- {
- Console::SetCursorPosition(j, i);
- Console::BackgroundColor = ConsoleColor::DarkRed;
- Console::ForegroundColor = ConsoleColor::Gray;
- if (i == 6 && j == 21)
- {
- Console::BackgroundColor = ConsoleColor::Gray;
- Console::ForegroundColor = ConsoleColor::DarkRed;
- cout << " Aviso importante del ANTIVIRUS: ";
- }
- else if (i == 8 && j == 14)
- cout << "Encontre un virus en 0x732f131 !";
- else if (i == 9 && j == 14)
- cout << "Lo borre ya que queria corromper el sistema.";
- else if (i == 10 && j == 14)
- cout << "No necesitas agradecermelo. Total, es solo un juego.";
- else if (i == 21 && j == 14)
- cout << "Perdiste. Pulsa cualquier tecla para ser derrotado...";
- }
- }
- _getch();
- }
- int main()
- {
- bool *es_enter, *es_esc, *tiene_llave, *uso_pocion, *game_over, *ouch;
- int *scancode, *menu_state, *game_state, *hp_jugador, *cant_pociones,
- *dmg, *id_enemigo, *hp_enemigo, *fila, *columna, **display,
- *fila_mapa, *columna_mapa, **mapa, *nivel, *dir, *pos_i, *pos_j, *to_draw,
- *ataque;
- scancode = new int; // es el scancode de las teclas ingresadas
- menu_state = new int; // que opcion se selecciono en el menu
- es_enter = new bool; // si se presiono enter
- es_esc = new bool; // si se presiono esc
- game_state = new int; // que pantalla (menu, juego o ayuda) se esta mostrando
- tiene_llave = new bool; // si tiene la llave
- uso_pocion = new bool; // si uso una pocion
- cant_pociones = new int; // cantidad de pociones que tiene
- hp_jugador = new int; // la vida del jugador (0-5)
- dmg = new int; // el danio del jugador
- ataque = new int; *ataque = 0; // ataque del jugador
- ouch = new bool; *ouch = false; // determina si el jugador sufre danio
- game_over = new bool; *game_over = false;
- id_enemigo = new int; // la identificacion del enemigo
- hp_enemigo = new int; *hp_enemigo = 0;// la vida del enemigo
- fila = new int; *fila = 20; // para fichas de 5x5
- columna = new int; *columna = 50; // para fichas de 5x5
- fila_mapa = new int; *fila_mapa = *fila / 5;
- columna_mapa = new int; *columna_mapa = *columna / 5;
- nivel = new int; *nivel = 1; // el mapa que se va a imprimir
- dir = new int; // direccion de movimiento del personaje
- pos_i = new int; *pos_i = 2;
- pos_j = new int; *pos_j = 2;
- to_draw = new int; *to_draw = 1111;
- /*indica que parte de la pantalla del juego tiene que re-dibujar, para que no parpadee toda la pantalla
- 0000 nada
- 1000 mapa & marco
- 0100 status (hp, nivel, etc.)
- 0010 texto
- 0001 personaje
- */
- Console::CursorVisible = false;
- *es_enter = false;
- *es_esc = false;
- *menu_state = 0;
- *game_state = 0;
- *hp_jugador = 5;
- *cant_pociones = 0;
- *dmg = 0;
- *tiene_llave = false;
- *uso_pocion = false;
- *id_enemigo = 0;
- MenuPrincipal(menu_state, game_state);
- display = CrearMatriz(fila, columna); // la matriz que sa va a imprimir
- mapa = CrearMatriz(fila_mapa, columna_mapa);
- srand(time_t());
- while (*hp_jugador != 0 && !*game_over)
- {
- if (_kbhit() != 0 && *game_state == 1)
- Captura(menu_state, es_enter, scancode, es_esc, game_state, uso_pocion, id_enemigo, nivel, dir, to_draw, dmg, hp_jugador, game_over);
- else if (*game_state != 1)
- Captura(menu_state, es_enter, scancode, es_esc, game_state, uso_pocion, id_enemigo, nivel, dir, to_draw, dmg, hp_jugador, game_over);
- switch (*game_state)
- {
- case 0:
- MenuPrincipal(menu_state, game_state);
- *to_draw = 1111;
- break;
- case 1:
- if (*to_draw / 1000 == 1)
- {
- GenerarMapa(mapa, fila_mapa, columna_mapa, nivel);
- GenerarMatriz(display, mapa, fila_mapa, columna_mapa);
- Dibujante(game_state, hp_jugador, cant_pociones, dmg, tiene_llave, uso_pocion, id_enemigo, hp_enemigo, display, fila, columna, nivel, pos_i, pos_j);
- }
- if ((*to_draw % 1000) >= 100)
- Estado(hp_jugador, cant_pociones, dmg, tiene_llave, uso_pocion);
- if ((*to_draw % 100) >= 10)
- Texto(id_enemigo, hp_enemigo, dmg, ouch, ataque);
- if ((*to_draw % 10) == 1)
- MoverPersonaje(pos_i, pos_j, dir, display);
- if (*to_draw != 0)
- *to_draw = 0;
- InteractuarConPersonaje(display, pos_i, pos_j, to_draw, nivel, tiene_llave, cant_pociones, dmg, id_enemigo, hp_enemigo, ataque, ouch, hp_jugador, game_over);
- break;
- case 2:
- PantallaAyuda(game_state);
- break;
- case 3:
- delete[] display, mapa;
- delete es_enter, es_esc, tiene_llave, uso_pocion, game_over,
- ouch, scancode, menu_state, game_state, hp_jugador, cant_pociones,
- dmg, id_enemigo, hp_enemigo, fila, columna, fila_mapa, columna_mapa,
- nivel, dir, pos_i, pos_j, to_draw, ataque;
- exit(0); // cierra el programa con codigo 0 (return 0)
- break;
- }
- }
- if (*hp_jugador < 1)
- Perdiste();
- else
- Ganaste();
- delete[] display, mapa;
- delete es_enter, es_esc, tiene_llave, uso_pocion, game_over,
- ouch, scancode, menu_state, game_state, hp_jugador, cant_pociones,
- dmg, id_enemigo, hp_enemigo, fila, columna, fila_mapa, columna_mapa,
- nivel, dir, pos_i, pos_j, to_draw, ataque;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement