JUEGO CONCENTRECE PARA ENTORNO DEV C++

6
#include<iostream.h> #include<ctype.h> #include<time.h> #include<windows.h> #include<math.h> #include<conio.h> #include <cstdlib> //###################################################################### int e,i,j,q,m,n,x=0,fila1,columna1,fila2,columna2,puntaje=0; char rand_1[16]={'1','2','3','4','5','1','6','7','8','2','6','7','8','3','4','5'};//variables usadas struct caractmen { char ch[5][5]; }; char vjugar; caractmen char_1[2]; void juegoterminado(); void primervalor(); void segundovalor(); void delay(long seconds) ; void gotoxy(int x, int y); void valorpuntaje(); void nuevalinea(int y); void output_1(); void num_1(); void num_2(); void main_1(); void slide_horz_right( int x ,int y , char ch[]); void tiempo(unsigned int mseconds); /*************************************************************************************** ********/ int main()// generara { srand((unsigned)time(0)); using std::random_shuffle; random_shuffle(rand_1,rand_1+16); for( m=1 ; m<5 ; m++) { for ( n=1 ; n<5 ; n++) { do { char_1[1].ch[m][n]=*(rand_1+x); x++; break; }while(x<16); } } char_1[0].ch[0][0]=' '; for ( int u=1 ; u<5 ; u++) { char_1[0].ch[0][u]=48+u; char_1[0].ch[u][0]=48+u;

Transcript of JUEGO CONCENTRECE PARA ENTORNO DEV C++

Page 1: JUEGO CONCENTRECE PARA ENTORNO DEV C++

#include<iostream.h> #include<ctype.h> #include<time.h> #include<windows.h> #include<math.h> #include<conio.h> #include <cstdlib> //###################################################################### int e,i,j,q,m,n,x=0,fila1,columna1,fila2,columna2,puntaje=0; char rand_1[16]={'1','2','3','4','5','1','6','7','8','2','6','7','8','3','4','5'};//variables usadas struct caractmen { char ch[5][5]; }; char vjugar; caractmen char_1[2]; void juegoterminado(); void primervalor(); void segundovalor(); void delay(long seconds) ; void gotoxy(int x, int y); void valorpuntaje(); void nuevalinea(int y); void output_1(); void num_1(); void num_2(); void main_1(); void slide_horz_right( int x ,int y , char ch[]); void tiempo(unsigned int mseconds); /***************************************************************************************

********/ int main()// generara { srand((unsigned)time(0)); using std::random_shuffle; random_shuffle(rand_1,rand_1+16); for( m=1 ; m<5 ; m++) { for ( n=1 ; n<5 ; n++) { do { char_1[1].ch[m][n]=*(rand_1+x); x++; break; }while(x<16); } } char_1[0].ch[0][0]=' '; for ( int u=1 ; u<5 ; u++) { char_1[0].ch[0][u]=48+u; char_1[0].ch[u][0]=48+u;

Page 2: JUEGO CONCENTRECE PARA ENTORNO DEV C++

for(int y=1 ; y<5 ; y++) { char_1[0].ch[u][y]='*'; } }

{ system("color f3"); cout<< " \t"<<" 1 2 3 4"<<endl<<endl<<endl; for( i=1 ; i<5 ; i++) { cout<<" \t\t\t"; for ( j=0 ; j<5 ; j++) { cout<<char_1[0].ch[i][j]<<" "; } cout<<endl<<endl<<endl; } } nuevalinea(3); main_1(); nuevalinea(4); } /***************************************************************************************

********/ void num_1() { primervalor(); system("cls"); output_1(); valorpuntaje(); nuevalinea(1); num_2(); } /***************************************************************************************

********/ void num_2() { segundovalor(); system("cls"); if(fila1==fila2&&columna1==columna2) { char_1[0].ch[fila1][columna1]='*'; output_1(); valorpuntaje(); nuevalinea(3); cout<<"Error\n\nINGRESASTE POSICIONES IGUALES!!!!\n\nCASTIGO DE CUATRO

PUNTOS"<<endl<<endl<<endl; delay(3000); system("cls"); output_1(); valorpuntaje(); nuevalinea(3); num_1();

Page 3: JUEGO CONCENTRECE PARA ENTORNO DEV C++

system("cls"); puntaje-=4; } } /***************************************************************************************

********/ void primervalor() //ingresar el primer punto { printf("Ingrese las cordenadas del punto que desea ver \n"); cout<<"FILA NUMERO... "; cin>>fila1; cout<<"COLUMNA NUMERO... "; cin>>columna1; if(columna1>4||fila1>4) { printf("\nCORDENADAS INCORRECTAS\n\nINGRESE VALORES ENTRE 1 y 4\n\n"); primervalor(); } cout<<endl<<endl; if(char_1[0].ch[fila1][columna1]==' ') { system("cls"); output_1(); printf("Error\n\nESTE PUNTO YA ESTA DESIFRADO INGRESA NUEVAS CORDENADAS

\n\n"); primervalor(); } cout<<endl<<endl; char_1[0].ch[fila1][columna1]=char_1[1].ch[fila1][columna1]; } /***************************************************************************************

********/ void segundovalor() //ingresar el segundo punto { nuevalinea(2); printf("Ingrese las cordenadas del punto que desea ver \n\n"); cout<<"FILA NUMERO... "; cin>>fila2; cout<<"COLUMNA NUMERO... "; cin>>columna2; if(columna2>4||fila2>4) { printf("\nCORDENADAS INCORRECTAS\n\nINGRESE VALORES ENTRE 1 y 4\n\n"); segundovalor(); } cout<<endl<<endl; if(char_1[0].ch[fila2][columna2]==' ') { system("cls"); output_1(); printf("Error\n\nESTE PUNTO YA ESTA DESIFRADO INGRESA NUEVAS CORDENADAS\n\n"); segundovalor(); } cout<<endl<<endl; char_1[0].ch[fila2][columna2]=char_1[1].ch[fila2][columna2]; }

Page 4: JUEGO CONCENTRECE PARA ENTORNO DEV C++

/***************************************************************************************

********/ void output_1() //mostrar la pantalla principal del juego { for( e=0 ; e<5 ; e++) { cout<<" \t\t\t"; for(q=0 ; q<5 ; q++) { cout<<char_1[0].ch[e][q]<<" "; } cout<<endl<<endl<<endl; } } /***************************************************************************************

********/ void main_1() { valorpuntaje(); gotoxy(1,20); num_1(); output_1(); valorpuntaje(); if(char_1[1].ch[fila1][columna1]==char_1[1].ch[fila2][columna2]) { gotoxy(1,20); cout<<"ENCONTRASTE UNA PAREJA,,BIEN¡¡¡\n\n TIENES DIEZ PUNTOS¡¡"<<endl; char_1[0].ch[fila1][columna1]=' '; char_1[0].ch[fila2][columna2]=' '; puntaje+=10; } else { gotoxy(1,20); printf("FALLASTE, INTENTA OTRA VEZ\n\nCASTIGO DE DOS PUNTOS"); nuevalinea(5); puntaje-=2; } if(char_1[1].ch[fila1][columna1]!=char_1[1].ch[fila2][columna2]) { char_1[0].ch[fila1][columna1]='*','*'; char_1[0].ch[fila2][columna2]='*','*'; } tiempo(1600); system("cls"); output_1(); valorpuntaje(); for (i=1 ; i<2 ; i++) { for ( j=1 ; j<2 ; j++) { if (char_1[0].ch[i][j]==' '&&char_1[0].ch[i][j+1]==' '&&char_1[0].ch[i][j+2]=='

'&&char_1[0].ch[i][j+3]==' '&&char_1[0].ch[i+1][j]==' '&&char_1[0].ch[i+1][j+1]=='

'&&char_1[0].ch[i+1][j+2]==' '&&char_1[0].ch[i+1][j+3]==' '&&char_1[0].ch[i+2][j]=='

'&&char_1[0].ch[i+2][j+1]==' '&&char_1[0].ch[i+2][j+2]==' '&&char_1[0].ch[i+2][j+3]=='

Page 5: JUEGO CONCENTRECE PARA ENTORNO DEV C++

'&&char_1[0].ch[i+3][j]==' '&&char_1[0].ch[i+3][j+1]==' '&&char_1[0].ch[i+3][j+2]=='

'&&char_1[0].ch[i+3][j+3]==' ') { cout<<"\n\nGanaste!! tu puntaje es... "<<puntaje<<endl<<endl; cout<<"QUIERES INICIAR UN NUEVO JUEGO?(s/n)"; cin>>vjugar; vjugar=tolower(vjugar); while(isdigit(vjugar)) { cout<<"ESCOGE UNA OPCION"; cin>>vjugar; } if (vjugar=='s') { puntaje=0; x=0; system("cls"); main(); } if (vjugar=='n') { cout<<"JUEGO TERMINADO"; exit(0); } else { exit(0); } } } } main_1(); } /***************************************************************************************

********/ void nuevalinea(int y) //hace el numero de nuevas lineas { for (e=0 ; e<y ; e++) cout<<endl; } /***************************************************************************************

********/ void delay(long seconds) //Esta funcion es para hacer una pantalla de tiempo { clock_t time1 = clock(); // usar hora del sistema clock_t time2 = time1 + seconds; while(time1 < time2) time1 = clock(); return; } /***************************************************************************************

********/ void valorpuntaje(){ //con esto actualizamos puntaje gotoxy(64,17); cout<<"Puntaje = "<<puntaje<<endl; }

Page 6: JUEGO CONCENTRECE PARA ENTORNO DEV C++

/***************************************************************************************

********/ void tiempo(unsigned int mseconds) { clock_t goal = mseconds + clock(); while (goal > clock()); } /***************************************************************************************

********/ /***************************************************************************************

********/ void slide_horz_right( int x ,int y , char ch[]) //Esta funcion es para mover el texto en la

pantalla { for ( int i=1 ; i<x ; i++) { gotoxy(i,y); { cout<<ch<<endl; cout<<" "; delay(25); } gotoxy(64,47); } } /***************************************************************************************

********/