#include #include #include #include #include #define IZQUIERDA 75 #define DERECHA 77 #define ARRIBA 72 #define ejey 23 char dibujo_1[]={' ',' ','*',' ',' ',0}; char dibujo_2[]={' ','*','*','*',' ',0}; char dibujo_3[]={'*',' ','=',' ','*',0}; char morir_1[]={'#','#',' ','#','#',0}; char morir_2[]={' ',' ','#',' ',' ',0}; char morir_3[]={'#','#',' ','#','#',0}; char morir_4[]={' ',' ','#',' ',' ',0}; char morir_5[]={'#','#',' ','#','#',0}; char morir_6[]={' ',' ','#',' ',' ',0}; char limpiar[]= {' ',' ',' ',' ',' ',0}; char opcion; int x=40, y=22; int d=0; int xd; bool disparo = false; int puntaje=0; int vida=1; int corazon=3; int level=100; int levell=1; int sumar=0; //posicion de asteroides int ran; int ya= 8, xa= 12; int yb= 12, xb= 18; int yx= 6, xx= 58; int yc= 10, xc= 70; //prototipo de funciones void vidas(int); void salud(int); void nivel(int); void random(); void jugar(); void lineas(); void datos(); void morir(); //dibujo que aparece cuendo la nave explota void morir() { textcolor(RED); gotoxy(x,y); puts(morir_1); gotoxy(x,y+1); puts(morir_2); gotoxy(x,y+2); puts(morir_3); Sleep(380); gotoxy(x,y); puts(morir_4); gotoxy(x,y+1); puts(morir_5); gotoxy(x,y+2); puts(morir_6); Sleep(380); gotoxy(x,y); puts(dibujo_1); gotoxy(x,y+1); puts(dibujo_2); gotoxy(x,y+2); puts(dibujo_3); textcolor(WHITE); corazon = 3; } //las vidas que nos quedan void vidas(int vida) { gotoxy(34,1); printf("Vidas: %d",vida); } //dibuja los corazones que tenemos void salud(int salud) { textcolor(RED); gotoxy(70,1); printf(" "); gotoxy(71,1); printf(" "); gotoxy(72,1); printf(" "); int c; for(c=0;c= y+d && xa == xd+2)) { ya=4; d=0; puntaje+=10; disparo = false; random(); xa = ran; /*if(xd+2 == x && y + d -1 == y) {puntaje -=10; corazon--; salud(corazon); }*/ } if(ya > ejey) { random(); xa = ran; ya = 4; sumar++; } if(yb > ejey) { yb=4; random(); xb= ran; sumar++; } if(yb >= y+d && xb == xd+2) { yb=4; d=0; puntaje+=10; disparo = false; random(); xb = ran; } if(yx > ejey) { yx=4; random(); xx=ran; sumar++; } if(yx >= y+d && xx == xd+2) { yx=4; d=0; puntaje+=10; disparo = false; random(); xx=ran; } if(yc > ejey ) { yc=4; random(); xc=ran; sumar++; } if(yc >= y+d && xc == xd+2) { yc=4; d=0; puntaje+=10; disparo = false; random(); xc=ran; } //fin del recorrido y de la colicion con disparo // nivel: gotoxy(18,1);printf(" "); gotoxy(18,1);printf("Nivel: %d",levell); if(sumar == 10) { level -=5; //cada 10 asteroides que toquen el suelo la variable level decrementa 5 levell++; sumar=0; } //fin nivel //colicion del avion con asteriodes if((xa < x+5 && xa > x-1 && ya== y) || (xb < x+5 && xb > x-1 && yb== y) || (xc < x+5 && xc > x-1 && yc== y)|| (xx < x+5 && xx > x-1 && yx== y)) { corazon--; salud(corazon); printf("\a"); if(corazon ==0) { corazon=3; vida--; morir(); salud(corazon); vidas(vida); } } //no desaparece el avion en el momento de la colocion gotoxy(x,y); puts(dibujo_1); gotoxy(x,y+1); puts(dibujo_2); gotoxy(x,y+2); puts(dibujo_3); //aumenta Y para que bajen los asteroides ya+=1; yb+=1; yx+=1; yc+=1; // movimiento de la nave, mas disparo if(kbhit()) { char tecla=getch(); switch(tecla) { case IZQUIERDA: gotoxy(x,y); puts(limpiar); gotoxy(x,y+1); puts(limpiar); gotoxy(x,y+2); puts(limpiar); x -=2; if(x <= 2) // si x es menor a 2 el avion queda en la posicion 2 para no irse de la pantalla {x=2;} gotoxy(x,y); puts(dibujo_1); gotoxy(x,y+1); puts(dibujo_2); gotoxy(x,y+2); puts(dibujo_3); break; case DERECHA: gotoxy(x,y); puts(limpiar); gotoxy(x,y+1); puts(limpiar); gotoxy(x,y+2); puts(limpiar); x +=2; if(x >=75) // si x es mayor a 75 el avion queda en la posicion 75 para no irse de la pantalla { x=75; } gotoxy(x,y); puts(dibujo_1); gotoxy(x,y+1); puts(dibujo_2); gotoxy(x,y+2); puts(dibujo_3); break; case ARRIBA: disparo = true; break; }// fin switch }//fin if kbhit() } void lineas() { int i; char linea[]={'_',0}; char lineav[]={'|',0}; int xl=2, yl=3; for(i=xl;i <= 79;i++) { gotoxy(i,yl); puts(linea); } for(i = xl;i <= 79;i++) { gotoxy(i,25); puts(linea); } for(i=yl+1;i <= 25;i++) { gotoxy(1,i); puts(lineav); } for(i=yl+1;i <= 25;i++) { gotoxy(80,i); puts(lineav); } } void main() { //dibuja la nave para que aparesca de un primer momento //HACER PRESENTACION int menu; do { system("color B"); for(y=1;y<79;y++)cout<<"="; for(x=1;x<22;x++) { cout<<"\n||"; for(y=1;y<38;y++) cout<<" "; for(y=1;y<38;y++) cout<<" "; cout<<"||"; } cout<<"\n"; for(y=1;y<79;y++) cout<<"="; cout<<"\n\n"; system("color B"); gotoxy(17,3);cout<<" JUEGO DE NAVES "; gotoxy(17,5);cout<<" ° "; gotoxy(17,6);cout<<" * * °°° * * "; gotoxy(17,7);cout<<" * °°°°° * "; gotoxy(17,8);cout<<" °°°ø°°° "; gotoxy(17,9);cout<<"* * °°°°°°°°° * * "; gotoxy(18,10);cout<<" °°°°°ø°°°°° "; gotoxy(18,11);cout<<" * **°°°°°°°°°°°°°** * "; gotoxy(18,12);cout<<" ***°°°°°°°ø°°°°°°°*** * "; gotoxy(18,13);cout<<" * ****°°°°°°°°°°°°°°°°°**** "; gotoxy(18,14);cout<<" *** ::: ::: *** "; gotoxy(18,15);cout<<" * ** : : : : : : ** * "; gotoxy(18,16);cout<<" * * : : : : : : * "; gotoxy(5,18); cout<<"1. Juego"; gotoxy(5,19); cout<<"2. Acerca de.."; gotoxy(5,20); cout<<"3. Salir"; gotoxy(5,22); cout<<"Escriba la opcion que eligio: "; cin>>menu; switch(menu) { case 1: clrscr(); gotoxy(x,y); puts (dibujo_1); gotoxy(x,y+1); puts (dibujo_2); gotoxy(x,y+2); puts (dibujo_3); vidas(vida); lineas(); salud(corazon); while(vida > 0){jugar();} break; case 2: datos(); break; case 3: exit(3); break; } } while (toupper(opcion)=='N'); gotoxy(35,15);cout<<"GAME OVER"; getch(); return ; } void datos() { int x,y; do { clrscr(); system("color B1"); gotoxy(30,2); cout<<"\tDATOS"<>opcion; clrscr(); } while (toupper(opcion)== 'S'); return; }