#include <iostream>
#include <cstdlib>
#include <ctime>
class Humano {
public:
void mensaje() const {
std::cout << "¡Soy un humano y estoy a salvo!" << std::endl;
};
class Zombie {
public:
void mensaje() const {
std::cout << "¡Soy un zombie y te atrapé!" << std::endl;
};
class Juego {
private:
char matriz[4][4]; // Matriz de juego
int humanos;
int zombies;
public:
Juego() : humanos(0), zombies(0) {
// Inicializar la matriz con valores aleatorios (0, 1, 2)
std::srand(std::time(0));
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j) {
matriz[i][j] = std::rand() % 3;
if (matriz[i][j] == 0) {
zombies++;
} else if (matriz[i][j] == 1) {
humanos++;
void mostrarMatriz() const {
std::cout << "Matriz de juego:" << std::endl;
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j) {
char c;
if (matriz[i][j] == 0) {
c = 'Z'; // Zombie
} else if (matriz[i][j] == 1) {
c = 'H'; // Humano
} else {
c = 'V'; // Vacío
std::cout << c << " ";
std::cout << std::endl;
}
void jugar() {
char nombre[50];
std::cout << "Ingrese su nombre: ";
std::cin >> nombre;
std::cout << "¡Bienvenido, " << nombre << "!" << std::endl;
while (true) {
mostrarMatriz();
int fila, columna;
std::cout << "Ingrese la fila (0-3): ";
std::cin >> fila;
std::cout << "Ingrese la columna (0-3): ";
std::cin >> columna;
if (fila < 0 || fila >= 4 || columna < 0 || columna >= 4) {
std::cout << "Posición inválida. Intente de nuevo." << std::endl;
continue;
if (matriz[fila][columna] == 'H') {
humanos--;
Humano humano;
[Link]();
} else if (matriz[fila][columna] == 'Z') {
zombies--;
Zombie zombie;
[Link]();
} else {
std::cout << "Posición vacía. Sigue buscando." << std::endl;
matriz[fila][columna] = 'O'; // Marcamos la posición como revisada
if (humanos == 0) {
std::cout << "¡Felicidades, has rescatado a todos los humanos! Has
ganado." << std::endl;
break;
} else if (zombies == 0) {
std::cout << "¡Oh no, todos los humanos han sido atrapados por
los zombies! Has perdido." << std::endl;
break;
char jugarNuevamente;
std::cout << "¿Quieres jugar de nuevo? (S/N): ";
std::cin >> jugarNuevamente;
if (jugarNuevamente != 'S' && jugarNuevamente != 's') {
std::cout << "Gracias por jugar. ¡Hasta luego!" << std::endl;
exit(0);
};
int main() {
Juego juego;
[Link]();
return 0;