Documentos de Académico
Documentos de Profesional
Documentos de Cultura
#include <windows.h>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <conio.h>
#include <string>
// Simbolos o Caracteres
#define CARACTER_FANTASMA 2
// Dirección de pacman
#define DIRECCION_IZQUIERDA 0
#define DIRECCION_DERECHA 1
#define DIRECCION_ARRIBA 2
#define DIRECCION_ABAJO 3
#define DIRECCION_INVALIDA -1
#define NADA 0
#define FILAS_MAPA 25
#define COLUMNAS_MAPA 29
#define LIMITE_IZQUIERDO 1
#define LIMITE_SUPERIOR 0
#define VIDAS_PACMAN 3
#define CARACTER_PACMAN 2
#define MODO_PRESA 1001 // Este modo es cuando pacman ha comida la píldora mágica
#define MODO_INVISIBLE 1002 // Este modo es cuando el fantasma ha sido comido por pacman
y está regresando a su casa
#define TIEMPO_ZOMBIE 50
int backcolor = 0;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
char mapa[FILAS_MAPA][COLUMNAS_MAPA + 1] = {
"ahhhhhhhhhhhhhnhhhhhhhhhhhhhb",
"v@············v············@v",
"v·ahhb·ahhhhb·v·ahhhhb·ahhb·v",
"v·chhd·chhhhd·v·chhhhd·chhd·v",
"v···························v",
"v·hhhh·v·hhhhhnhhhhh·v·hhhh·v",
"v······v······v······v······v",
"chhhhb·phhhhh·v·hhhhho·ahhhhd",
"hhhhhd·v·v 2 v·v·chhhhh",
"·········v 2 v·········",
"hhhhhb·v·v 2 v·v·ahhhhh",
"ahhhhd·v·hhhhhnhhhhh·v·chhhhb",
"v·············v·············v",
"v·hhhb·hhhhhh·v·hhhhhh·ahhh·v",
"v····v·················v····v",
"phhh·v·v·hhhhhnhhhhh·v·v·hhho",
"v······v······v······v······v",
"v·hhhhhmhhhhh·v·hhhhhmhhhhh·v",
"v@·························@v",
"chhhhhhhhhhhhhhhhhhhhhhhhhhhd",
};
/* v : vertical
h: horizontal
int cantidad_comida = 290; // Guarda la cantidad de comida que hay en el mapa al principio del
juego
// Esta matriz va a guardar todos los moviemientos hacia donde se va pacman. Si es que
// pacman no pasó por algún lugar, simplemente se le asigna el caracter a que significa
// aleatorio
short matriz_movimientos[FILAS_MAPA][COLUMNAS_MAPA];
class PERSONAJE;
class PACMAN;
class FANTASMA;
class PERSONAJE {
private:
int simbolo;
string nombre;
int direccion;
0 IZQUIERDA : DIRECCION_IZQUIERDA
1 DERECHA : DIRECCION_DERECHA
2 ARRIBA : DIRECCION_ARRIBA
3 ABAJO : DIRECCION_ABAJO
-1 NO SE MUEVE : DIRECCION_INVALIDA
*/
int color;
public:
void setX(int);
void setY(int);
void setSimbolo(int);
void setDireccion(int);
int getX();
int getY();
string getNombre();
void setNombre(string);
int getColor();
void setColor(int);
int getAnteriorX();
int getAnteriorY();
int getXRelativoAlMapa();
int getYRelativoAlMapa();
int getAnteriorXRelativoAlMapa(); // Obtiene las coordenadas anteriores relativas al mapa
int getAnteriorYRelativoAlMapa();
int getSimbolo();
int getDireccion();
void borrar();
int direccionVerdadera(int);
private:
int puntaje;
public:
int getPuntaje();
void actualizar_puntaje();
int getVidas();
void setSigueJugando(bool);
bool getSigueJugando();
void imprimirVidas();
void reiniciaCoordenadas();
bool comioPildora();
private:
int temporizador;
bool temporizador_activado;
public:
void mover();
int getModo();
void setColorPredeterminado();
int getTemporizador();
void setTemporizador(int temporizador);
private:
public:
FANTASMA_ROJO();
void reiniciar_coordenadas();
};
private:
public:
FANTASMA_ROSADO();
void reiniciar_coordenadas();
};
private:
public:
FANTASMA_CELESTE();
void reiniciar_coordenadas();
};
class FANTASMA_VERDE : public FANTASMA {
private:
public:
FANTASMA_VERDE();
void reiniciar_coordenadas();
};
// Funciones
int main()
empezar_juego();
return 0;
void empezar_juego()
system("color");
// Inicializo la matriz que guarda los movimientos de pacman con -1 (es decir, aleatorio)
inicializaMatrizMovimientos();
// Creamos al pacman
PACMAN pacman;
FANTASMA_ROJO f1;
FANTASMA_ROSADO f2;
FANTASMA_CELESTE f3;
FANTASMA_VERDE f4;
// Guardamos los fantasmas en un vector de fantasmas
fantasmas.push_back(f1);
fantasmas.push_back(f2);
fantasmas.push_back(f3);
fantasmas.push_back(f4);
pacman.pintar();
pacman.imprimirVidas();
int tecla_salir;
reinicia_personajes(pacman, fantasmas);
do {
// Esto es antes de actualizar el puntaje porque al actualizar el puntaje se borra las comidas
pacman.mover(tecla); // Movemos a pacman (Lo hago así para que pacman siempre esté
pintado detrás de los fantasmas al ser comido)
fantasmas[i].mover();
cout << "\a"; Sleep(1000); // Se hace una pausita luego del choque
reinicia_personajes(pacman, fantasmas);
// Pintamos al mapa
pacman.pintar();
fantasmas[i].pintar();
pacman.imprimirVidas();
do {
if (tecla == 's')
sal = true;
} while (!sal);
} // fin de if
// Una vez llegado a su casa, debe de volver su estado a modo CAZADOR y empezar con sus
coordenadas iniciales
///////////////////////////
// Por ahora simplemente haré que cuando un fantasma sea comido, aparezca
inmediatamente en su casa
// Luego investigaré sobre como hacer para que el fantasma regrese a su casa
/*********************************************************************/
fantasma->reiniciar_coordenadas(); // Regresamos al fantasma a su casa (posición inicial)
/*********************************************************************/
} else {
if (pacman.estadoFinalPacman() == PACMAN_GANADOR) {
do {
if (tecla == 's')
sal = true;
} while (!sal);
return;
}
/*
if (tecla == 's') {
tecla = pacman.getDireccion();
cout << "Seguro que desea salir del juego (y/n)?: ";
tecla_salir = getche();
if (tecla_salir == 'y') {
return;
} else {
repintar = true; // para pintar el mapa solo cuando se haya paralizado el juego
*/
// Hace una cuenta regresiva en las coordenadas (x, y) y desde limite_inferior hasta
limite_superior
setCColor(BLANCO_BRILLANTE);
for (int i = limite_superior; i >= limite_inferior; --i) {
Sleep(750);
Sleep(750);
pacman.reiniciaCoordenadas();
pacman.setDireccion(DIRECCION_IZQUIERDA);
/* v : vertical
h: horizontal