Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream.h>
- #define RANGO 100
- #define MAX 12
- #define MIN 7
- int patata( int trial, int jug, int num ){
- int v;
- srand(time(NULL));
- if( jug == 1 ) num = (rand()%RANGO)+1;
- v = (rand()%(MIN-MAX)+MIN);
- jug = v;
- while( v>=0 && num!=trial ){
- scanf("%d",&trial);
- if( num<trial && v!=0 ) cout << " Menor que " << trial << " ";
- if( num>trial && v!=0 ) cout << " Mayor que " << trial << " ";
- if( v==0 && num!=trial ) cout << " \n Lo siento, has fallado, era " << num;
- if( num!=trial ) v--;
- }
- jug=jug-v+1;
- if( num==trial ) cout << " \n Correcto! Era " << num << " con " << jug << " intentos \n ";
- return jug;
- }
- int main(){
- FILE *records=fopen("Records patata caliente (2J).txt","a");
- int jug, try1, try2, num, trial=0, retry;
- char jug1[4], jug2[4];
- do{
- do{
- system("cls");
- cout << "\n -= La patata caliente =- \n 1 o 2 Jugadores? ";
- cin >> jug;
- }while( jug!=1 && jug!=2 && jug!=0 );
- if( jug==0 ) return 0;
- // MODO: UN JUGADOR
- if( jug==1 ){
- cout << " \n Averigua que numero estoy pensando entre 0 y 100: ";
- patata(trial,jug,num);
- }
- // MODO: DOS JUGADORES
- if( jug==2 ){
- // INICIALES JUGADORES
- cout << " \n Jugador 1, introduce tus iniciales: ";
- cin >> jug1;
- cout << " \n Jugador 2, introduce tus iniciales: ";
- cin >> jug2;
- // JUGADOR 1 JUEGA
- do{
- system("cls");
- cout << " \n -= Turno de " << jug1 << " =- ";
- cout << " \n " << jug2 << ", introduce un numero del 1 al " << RANGO << " cuando " << jug1 << " no mire: ";
- cin >> num;
- }while( num<1 || num>RANGO );
- system("cls");
- cout << " \n Bien, adivina el numero, " << jug1 << ": ";
- try1=patata(trial,jug,num);
- system("PAUSE");
- // JUGADOR 2 JUEGA
- do{
- system("cls");
- cout << " \n -= Turno de " << jug2 << " =- ";
- cout << " \n " << jug1 << ", introduce un numero del 1 al " << RANGO << " cuando " << jug2 << " no mire: ";
- cin >> num;
- }while( num<1 || num>RANGO );
- system("cls");
- cout << " \n Bien, adivina el numero, " << jug2 << ": ";
- try2=patata(trial,jug,num);
- system("PAUSE");
- // RESULTADOS
- system("cls");
- if(try1<try2){
- cout << " \n El ganador es " << jug1 << " con " << try1 << " intentos ";
- fprintf(records,"%s con %d puntos gano a %s con %d puntos el ",jug1,10*(MAX-try1),jug2,10*(MAX-try2));
- }
- if(try2<try1){
- cout << " \n El ganador es " << jug2 << " con " << try2 << " intentos ";
- fprintf(records,"%s con %d puntos gano a %s con %d puntos el ",jug2,10*(MAX-try2),jug1,10*(MAX-try1));
- }
- if(try1==try2){
- cout << " \n Empate con " << try1 << " intentos ";
- fprintf(records,"Hubo un empate entre %s y %s a %d puntos el ",jug1,jug2,10*(MAX-try1));
- }
- // SE APUNTAN LOS RECORDS CON FECHA
- time_t tiempo = time(NULL);
- struct tm *tlocal = localtime(&tiempo);
- char output[128];
- strftime(output,128,"%d/%m/%y a las %H:%M:%S",tlocal);
- fprintf(records,"%s\n",output);
- fclose(records);
- }
- cout << " \n Volver al menu(1=si)? ";
- cin >> retry;
- }while( retry==1 );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement