tengo este programa c++, pero a la hora de ejecutar la parte izquierda se queda atorado los "diamantes" ya busque en ciclo y modificando y no encuentro la solución..., tambien busque como usar la tecla spce en ascci para quitar opción de arriba y abajo, seria de gran ayuda si me pudieran ayudar a resolver y decir cual es mi error... !!
#include <windows.h>
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define ARR 72
#define ABA 80
#define IZQ 75
#define DER 77
char ave_l1[]={' ','*','*', '*',' ',' ',' ',0}; // dibujo de la nave
char ave_l2[]={' ','*','*', ' ','*',' ',' ',0};
char ave_l3[]={' ','*','*', '*',' ',' ',' ',0};
char explocion_l1[]={' ',' ','*','*',' ',' ',' ',0};
char explocion_l2[]={' ','*','*','*','*',' ',' ',0}; //explocion de la nave
char explocion_l3[]={' ',' ','*','*',' ',' ',' ',0};
char explocion_r1[]={'*',' ','*','*',' ','*',' ',0};
char explocion_r2[]={' ','*','*','*','*',' ',' ',0}; //la segunda explocion
char explocion_r3[]={'*',' ','*','*',' ','*',' ',0};
char borrar_ave[]={' ',' ',' ',' ',' ',' ',' ',0}; // cuando se borra
int Num_vidas = 3;
int Corazones = 3;
int ix = 1;
int iy = 19;
int y = 8, x = 12;
int yy = 70 , xx = 1;
int x1 = 58 , y1 = 6;
int x2 = 17, y2 = 9;
int i,v;
/*para cambiar de nivel*/
int repeticion = 0, nivel =1;
bool condicion = false;
void gotoxy(int x, int y)
{
HANDLE hCon;
COORD dwPos;
dwPos.X = x;
dwPos.Y = y;
hCon = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hCon,dwPos);
}
void vidas(int vi)
{
gotoxy(2,1); printf("VIDAS %d",vi);
}
void Barra_salud(int n)
{
gotoxy(72,1);printf(" ");
gotoxy(73,1);printf(" ");
gotoxy(74,1);printf(" ");
for(v = 0 ; v < n ; v++)
{
gotoxy(72+v,1);
printf("%c",3);
}
}
void Explocion(void)
{
gotoxy(ix,iy); puts(explocion_l1);
gotoxy(ix,iy+1); puts(explocion_l2);
gotoxy(ix,iy+2); puts(explocion_l3);
Sleep(380);
gotoxy(ix,iy); puts(explocion_r1);
gotoxy(ix,iy+1); puts(explocion_r2);
gotoxy(ix,iy+2); puts(explocion_r3);
Sleep(380);
gotoxy(ix,iy); puts(ave_l1);
gotoxy(ix,iy+1); puts(ave_l2);
gotoxy(ix,iy+2); puts(ave_l3);
}
void jugar(void)
{
//rutina de los diamantes
gotoxy(x,y); printf("%c",4);
gotoxy(xx,yy); printf("%c",4);
gotoxy(x1,y1); printf("%c",4);
gotoxy(x2,y2); printf("%c",4);
Sleep(80);
gotoxy(x,y); printf(" ");
gotoxy(xx,yy); printf(" ");
gotoxy(x1,y1); printf(" ");
gotoxy(x2,y2); printf(" ");
if (x > 20)
{
x = 2;
y = (rand() % 80) + 6;
if( x== 2);
condicion =false;
}
if(xx >20)
{
xx = 2;
yy = (rand() % 90) + 6;
}
if(x1 >20)
{
x1 = 2;
y1 = (rand() % 90) + 6;
}
if(x2 >20)
{
x2 = 2;
y2 = (rand() % 90) + 6;
}
//rutina de mover la ave
if (kbhit())
{
unsigned char tecla = getch();
switch (tecla)
{
case ARR:
if(iy > 4)
{
gotoxy(ix,iy);puts(borrar_ave);
gotoxy(ix,iy+1);puts(borrar_ave);
gotoxy(ix,iy+2);puts(borrar_ave);
iy -=2;//iy = iy -2;
gotoxy(ix,iy);puts(ave_l1);
gotoxy(ix,iy+1);puts(ave_l2);
gotoxy(ix,iy+2);puts(ave_l3);
}
break;
case ABA:
if( iy <70)
{
gotoxy(ix,iy);puts(borrar_ave);
gotoxy(ix,iy+1);puts(borrar_ave);
gotoxy(ix,iy+2);puts(borrar_ave);
iy +=2;//iy = iy +2;
gotoxy(ix,iy);puts(ave_l1);
gotoxy(ix,iy+1);puts(ave_l2);
gotoxy(ix,iy+2);puts(ave_l3);
}
break;
case IZQ:
if(ix > 4)
{
gotoxy(ix,iy);puts(borrar_ave);
gotoxy(ix,iy+1);puts(borrar_ave);
gotoxy(ix,iy+2);puts(borrar_ave);
ix -=2;//iy = iy -2;
gotoxy(ix,iy);puts(ave_l1);
gotoxy(ix,iy+1);puts(ave_l2);
gotoxy(ix,iy+2);puts(ave_l3);
}
break;
case DER:
if(ix <70)
{
gotoxy(ix,iy);puts(borrar_ave);
gotoxy(ix,iy+1);puts(borrar_ave);
gotoxy(ix,iy+2);puts(borrar_ave);
ix +=2;//iy = iy -2;
gotoxy(ix,iy);puts(ave_l1);
gotoxy(ix,iy+1);puts(ave_l2);
gotoxy(ix,iy+2);puts(ave_l3);
}
break;
} //fin del switch
}// Fin if
//rutina para golpes de metoritos
if(( x > ix && x<ix - 6 && y == iy-1)|| (x > ix && xx<ix - 6 && yy == iy-1)
|| (x1 > ix && xx<ix - 6 && y1 == iy-1)|| (x2 > ix && x2<ix - 6 && y2 == iy-1))
{
Corazones --;
Barra_salud(Corazones);
printf("\a");
}
gotoxy(ix,iy);puts(ave_l1);
gotoxy(ix,iy+1);puts(ave_l2);
gotoxy(ix,iy+2);puts(ave_l3);
if(!Corazones)
{
Num_vidas--;
vidas(Num_vidas);
Explocion();
Corazones =3;
Barra_salud(Corazones);
}
/*rutina para cambio de nivel*/
if(!condicion)
{
repeticion ++;
//condicionc = true;
}
if(repeticion == 10)
{
nivel++;
gotoxy(35,1); printf("NIVEL %i",nivel);
gotoxy(ix,iy); puts(borrar_ave);
gotoxy(ix,iy); puts(borrar_ave);
gotoxy(ix,iy); puts(borrar_ave);
iy -= 2; //iy = iy - 2;
gotoxy(ix,iy); puts(ave_l1);
gotoxy(ix,iy); puts(ave_l2);
gotoxy(ix,iy); puts(ave_l3);
repeticion = 0;
}
x--;
xx--;
x1--;
x2--;
}
int main ()
{
vidas(Num_vidas);
Barra_salud(Corazones);
gotoxy(35,1); printf("NIVEL %i",nivel);
gotoxy(ix,iy);puts(ave_l1);
gotoxy(ix,iy+1);puts(ave_l2);
gotoxy(ix,iy+2);puts(ave_l3);
while(Num_vidas > 0 && nivel <= 5 )
jugar();
gotoxy(22,16); printf("Game Over");
Sleep(120);
getch();
return 0;
}
#include <windows.h>
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define ARR 72
#define ABA 80
#define IZQ 75
#define DER 77
char ave_l1[]={' ','*','*', '*',' ',' ',' ',0}; // dibujo de la nave
char ave_l2[]={' ','*','*', ' ','*',' ',' ',0};
char ave_l3[]={' ','*','*', '*',' ',' ',' ',0};
char explocion_l1[]={' ',' ','*','*',' ',' ',' ',0};
char explocion_l2[]={' ','*','*','*','*',' ',' ',0}; //explocion de la nave
char explocion_l3[]={' ',' ','*','*',' ',' ',' ',0};
char explocion_r1[]={'*',' ','*','*',' ','*',' ',0};
char explocion_r2[]={' ','*','*','*','*',' ',' ',0}; //la segunda explocion
char explocion_r3[]={'*',' ','*','*',' ','*',' ',0};
char borrar_ave[]={' ',' ',' ',' ',' ',' ',' ',0}; // cuando se borra
int Num_vidas = 3;
int Corazones = 3;
int ix = 1;
int iy = 19;
int y = 8, x = 12;
int yy = 70 , xx = 1;
int x1 = 58 , y1 = 6;
int x2 = 17, y2 = 9;
int i,v;
/*para cambiar de nivel*/
int repeticion = 0, nivel =1;
bool condicion = false;
void gotoxy(int x, int y)
{
HANDLE hCon;
COORD dwPos;
dwPos.X = x;
dwPos.Y = y;
hCon = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hCon,dwPos);
}
void vidas(int vi)
{
gotoxy(2,1); printf("VIDAS %d",vi);
}
void Barra_salud(int n)
{
gotoxy(72,1);printf(" ");
gotoxy(73,1);printf(" ");
gotoxy(74,1);printf(" ");
for(v = 0 ; v < n ; v++)
{
gotoxy(72+v,1);
printf("%c",3);
}
}
void Explocion(void)
{
gotoxy(ix,iy); puts(explocion_l1);
gotoxy(ix,iy+1); puts(explocion_l2);
gotoxy(ix,iy+2); puts(explocion_l3);
Sleep(380);
gotoxy(ix,iy); puts(explocion_r1);
gotoxy(ix,iy+1); puts(explocion_r2);
gotoxy(ix,iy+2); puts(explocion_r3);
Sleep(380);
gotoxy(ix,iy); puts(ave_l1);
gotoxy(ix,iy+1); puts(ave_l2);
gotoxy(ix,iy+2); puts(ave_l3);
}
void jugar(void)
{
//rutina de los diamantes
gotoxy(x,y); printf("%c",4);
gotoxy(xx,yy); printf("%c",4);
gotoxy(x1,y1); printf("%c",4);
gotoxy(x2,y2); printf("%c",4);
Sleep(80);
gotoxy(x,y); printf(" ");
gotoxy(xx,yy); printf(" ");
gotoxy(x1,y1); printf(" ");
gotoxy(x2,y2); printf(" ");
if (x > 20)
{
x = 2;
y = (rand() % 80) + 6;
if( x== 2);
condicion =false;
}
if(xx >20)
{
xx = 2;
yy = (rand() % 90) + 6;
}
if(x1 >20)
{
x1 = 2;
y1 = (rand() % 90) + 6;
}
if(x2 >20)
{
x2 = 2;
y2 = (rand() % 90) + 6;
}
//rutina de mover la ave
if (kbhit())
{
unsigned char tecla = getch();
switch (tecla)
{
case ARR:
if(iy > 4)
{
gotoxy(ix,iy);puts(borrar_ave);
gotoxy(ix,iy+1);puts(borrar_ave);
gotoxy(ix,iy+2);puts(borrar_ave);
iy -=2;//iy = iy -2;
gotoxy(ix,iy);puts(ave_l1);
gotoxy(ix,iy+1);puts(ave_l2);
gotoxy(ix,iy+2);puts(ave_l3);
}
break;
case ABA:
if( iy <70)
{
gotoxy(ix,iy);puts(borrar_ave);
gotoxy(ix,iy+1);puts(borrar_ave);
gotoxy(ix,iy+2);puts(borrar_ave);
iy +=2;//iy = iy +2;
gotoxy(ix,iy);puts(ave_l1);
gotoxy(ix,iy+1);puts(ave_l2);
gotoxy(ix,iy+2);puts(ave_l3);
}
break;
case IZQ:
if(ix > 4)
{
gotoxy(ix,iy);puts(borrar_ave);
gotoxy(ix,iy+1);puts(borrar_ave);
gotoxy(ix,iy+2);puts(borrar_ave);
ix -=2;//iy = iy -2;
gotoxy(ix,iy);puts(ave_l1);
gotoxy(ix,iy+1);puts(ave_l2);
gotoxy(ix,iy+2);puts(ave_l3);
}
break;
case DER:
if(ix <70)
{
gotoxy(ix,iy);puts(borrar_ave);
gotoxy(ix,iy+1);puts(borrar_ave);
gotoxy(ix,iy+2);puts(borrar_ave);
ix +=2;//iy = iy -2;
gotoxy(ix,iy);puts(ave_l1);
gotoxy(ix,iy+1);puts(ave_l2);
gotoxy(ix,iy+2);puts(ave_l3);
}
break;
} //fin del switch
}// Fin if
//rutina para golpes de metoritos
if(( x > ix && x<ix - 6 && y == iy-1)|| (x > ix && xx<ix - 6 && yy == iy-1)
|| (x1 > ix && xx<ix - 6 && y1 == iy-1)|| (x2 > ix && x2<ix - 6 && y2 == iy-1))
{
Corazones --;
Barra_salud(Corazones);
printf("\a");
}
gotoxy(ix,iy);puts(ave_l1);
gotoxy(ix,iy+1);puts(ave_l2);
gotoxy(ix,iy+2);puts(ave_l3);
if(!Corazones)
{
Num_vidas--;
vidas(Num_vidas);
Explocion();
Corazones =3;
Barra_salud(Corazones);
}
/*rutina para cambio de nivel*/
if(!condicion)
{
repeticion ++;
//condicionc = true;
}
if(repeticion == 10)
{
nivel++;
gotoxy(35,1); printf("NIVEL %i",nivel);
gotoxy(ix,iy); puts(borrar_ave);
gotoxy(ix,iy); puts(borrar_ave);
gotoxy(ix,iy); puts(borrar_ave);
iy -= 2; //iy = iy - 2;
gotoxy(ix,iy); puts(ave_l1);
gotoxy(ix,iy); puts(ave_l2);
gotoxy(ix,iy); puts(ave_l3);
repeticion = 0;
}
x--;
xx--;
x1--;
x2--;
}
int main ()
{
vidas(Num_vidas);
Barra_salud(Corazones);
gotoxy(35,1); printf("NIVEL %i",nivel);
gotoxy(ix,iy);puts(ave_l1);
gotoxy(ix,iy+1);puts(ave_l2);
gotoxy(ix,iy+2);puts(ave_l3);
while(Num_vidas > 0 && nivel <= 5 )
jugar();
gotoxy(22,16); printf("Game Over");
Sleep(120);
getch();
return 0;
}