Pacman C++
Enviado por RodrigoSL • 26 de Abril de 2016 • Tarea • 2.793 Palabras (12 Páginas) • 206 Visitas
#include <windows.h>
#include <iostream>
#include <conio.h>
//#include <stdlib.h>
#include <stdio.h>
//#include <ctype.h>
//#pragma hdrstop
//#include <tchar.h>
//#pragma argsused
#define ARRIBA 72 // NUMEROS ASOCIADOS A LAS FLECHAS DEL TECLADO
#define IZQUIERDA 75
#define DERECHA 77
#define ABAJO 80
#define ESC 27
#define ENTER 13
int backcolor=0;
int dir = 0;
int x=39,y=22;
int anteriorpx,anteriorpy;
char tecla;
long int puntos = -5;
int vidas = 3;
void setCColor( int color)
{
static HANDLE hConsole;
hConsole = GetStdHandle( STD_OUTPUT_HANDLE );
SetConsoleTextAttribute( hConsole, color | (backcolor * 0x10 + 0x100) );
}
int color[7] = {
0x009,
0x00E,
0x00C,
0x002,
0x00B,
0x005,
0x00F
};
void gotoxy(int x, int y) // funcion que posiciona el cursos en la coordenada (x,y)
{
HANDLE hCon;
COORD dwPos;
dwPos.X = x;
dwPos.Y = y;
hCon = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hCon,dwPos);
}
char mapa[50][100] = {
" ",
" AXXXXXXXXXXXXXXXXXXXB AXXXXXXXXXXXXXXXXXXXB",
" Y___________________Y Y___________________Y",
" Y_AXXXXXB_AXXXXXXXB_Y Y_AXXXXXXXB_AXXXXXB_Y",
" Y_Y Y_Y Y_Y Y_Y Y_Y Y_Y",
" Y_DXXXXXC_DXXXXXXXC_DXC_DXXXXXXXC_DXXXXXC_Y",
" Y________|_________|___|_________|________Y",
" Y_AXXXXXB_AXB_AXXXXXXXXXXXXXB_AXB_AXXXXXB_Y",
" Y_DXXXXXC_Y Y_DXXXXB AXXXXC_Y Y_DXXXXXC_Y",
" Y_________Y Y______Y Y______Y Y_________Y",
" DXXXXXXXB_Y DXXXXB_Y Y_AXXXXC Y_AXXXXXXXC",
" Y_Y AXXXXC_DXXXC_DXXXXB Y_Y ",
" Y_Y Y_________________Y Y_Y ",
" XXXXXXXXC_DXC_AXXXXXX XXXXXXB_DXC_DXXXXXXXX",
" _________|____Y * Y____|_________",
" XXXXXXXXB_AXB_DXXXXXXXXXXXXXC_AXB_AXXXXXXXX",
" Y_Y Y_________________Y Y_Y ",
" Y_Y Y_AXXXXXXXXXXXXXB_Y Y_Y ",
" AXXXXXXXC_DXC_DXXXXB AXXXXC_DXC_DXXXXXXXB",
" Y________|_________Y Y_________|________Y",
" Y_AXXXXXB_AXXXXXXB_Y Y_AXXXXXXB_AXXXXXB_Y",
" Y_DXXXB Y_DXXXXXXC_DXXXC_DXXXXXXC_Y AXXXC_Y",
" Y_____Y Y_________|_____|_________Y Y_____Y",
" DXXXB_Y Y_AXB_AXXXXXXXXXXXXXB_AXB_Y Y_AXXXC",
" AXXXC_DXC_Y Y_DXXXXB AXXXXC_Y Y_DXC_DXXXB",
" Y_________Y Y______Y Y______Y Y_________Y",
" Y_AXXXXXXXC DXXXXB_Y Y_AXXXXC DXXXXXXXB_Y",
" Y_DXXXXXXXXXXXXXXC_DXXXC_DXXXXXXXXXXXXXXC_Y",
" Y_________________|_____|_________________Y",
" DXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXC",
};
void pintar_mapa()// Funcion que pinta el borde de la pantalla de juego
{
for(int i = 0 ; i < 78 ; i++){
for(int j = 0 ; j < 30 ; j++){
gotoxy(i,j);
if(mapa[j][i] == 'X') {setCColor(color[0]);printf("%c",205);}
if(mapa[j][i] == '_') {setCColor(color[1]); printf("%c",250);}
else if(mapa[j][i] == 'Y') {setCColor(color[0]);printf("%c",186);}
else if(mapa[j][i] == 'A') {setCColor(color[0]);printf("%c",201);}
else if(mapa[j][i] == 'B') {setCColor(color[0]);printf("%c",187);}
else if(mapa[j][i] == 'C') {setCColor(color[0]);printf("%c",188);}
else if(mapa[j][i] == 'D') {setCColor(color[0]);printf("%c",200);}
}
}
}
void pacman(int x , int y){
setCColor(color[1]);
gotoxy(x,y); printf("%c",2);
}
void borrar_pacman(int x, int y){
gotoxy(x,y); printf(" ");
if(mapa[y][x] == '_'){ mapa[y][x] = ' '; puntos += 5;}
}
void teclear(){
if(kbhit()){
tecla = getch();
switch(tecla){
case ARRIBA:
dir = 0;
break;
case ABAJO:
dir = 1;
break;
case DERECHA:
dir = 2;
break;
case IZQUIERDA:
dir = 3;
break;
}// FIN SWITCH
}// FIN DEL IF
}
class fantasma{
int fdir;
int _x, _y;
int col;
public:
fantasma(int x , int y , int color); // constructor
void dibujar_fantasma() const;
void borrar_fantasma() const;
void mover_fantasma();
void choque_pacman();
};
fantasma::fantasma(int x , int y, int color){
_x = x;
...