Advertisement
Kyrexar

La patata caliente

Dec 10th, 2012
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.59 KB | None | 0 0
  1. #include <iostream.h>
  2.  
  3. #define RANGO 100
  4. #define MAX 12
  5. #define MIN 7
  6.  
  7. int patata( int trial, int jug, int num ){
  8.     int v;
  9.    
  10.     srand(time(NULL));
  11.     if( jug == 1 ) num = (rand()%RANGO)+1;
  12.    
  13.     v = (rand()%(MIN-MAX)+MIN);
  14.     jug = v;
  15.  
  16.     while( v>=0 && num!=trial ){
  17.        scanf("%d",&trial);
  18.        if( num<trial && v!=0 ) cout << " Menor que " << trial << " ";
  19.        if( num>trial && v!=0 ) cout << " Mayor que " << trial << " ";
  20.        if( v==0 && num!=trial ) cout << " \n Lo siento, has fallado, era " << num;
  21.        if( num!=trial ) v--;
  22.     }
  23.     jug=jug-v+1;
  24.     if( num==trial ) cout << " \n Correcto! Era " << num << " con " << jug << " intentos \n ";
  25.     return jug;
  26. }
  27.  
  28. int main(){
  29.     FILE *records=fopen("Records patata caliente (2J).txt","a");
  30.     int jug, try1, try2, num, trial=0, retry;
  31.     char jug1[4], jug2[4];
  32.    
  33.     do{
  34.        do{
  35.           system("cls");
  36.           cout << "\n -= La patata caliente =- \n 1 o 2 Jugadores? ";
  37.           cin >> jug;
  38.        }while( jug!=1 && jug!=2 && jug!=0 );
  39.        if( jug==0 ) return 0;
  40.  
  41. // MODO: UN JUGADOR
  42.        if( jug==1 ){
  43.           cout << " \n Averigua que numero estoy pensando entre 0 y 100: ";
  44.           patata(trial,jug,num);
  45.           }
  46.  
  47. // MODO: DOS JUGADORES
  48.        if( jug==2 ){
  49.  
  50. // INICIALES JUGADORES
  51.            cout << " \n Jugador 1, introduce tus iniciales: ";
  52.            cin >> jug1;
  53.            cout << " \n Jugador 2, introduce tus iniciales: ";
  54.            cin >> jug2;
  55.  
  56. // JUGADOR 1 JUEGA
  57.            do{
  58.               system("cls");
  59.               cout << " \n -= Turno de " << jug1 << " =- ";
  60.               cout << " \n " << jug2 << ", introduce un numero del 1 al " << RANGO << " cuando " << jug1 << " no mire: ";
  61.               cin >> num;
  62.            }while( num<1 || num>RANGO );
  63.            system("cls");
  64.            cout << " \n Bien, adivina el numero, " << jug1 << ": ";
  65.            try1=patata(trial,jug,num);
  66.            system("PAUSE");
  67.  
  68. // JUGADOR 2 JUEGA
  69.            do{
  70.               system("cls");
  71.               cout << " \n -= Turno de " << jug2 << " =- ";
  72.               cout << " \n " << jug1 << ", introduce un numero del 1 al " << RANGO << " cuando " << jug2 << " no mire: ";
  73.               cin >> num;
  74.            }while( num<1 || num>RANGO );
  75.            system("cls");
  76.            cout << " \n Bien, adivina el numero, " << jug2 << ": ";
  77.            try2=patata(trial,jug,num);
  78.            system("PAUSE");
  79.  
  80. // RESULTADOS
  81.            system("cls");
  82.            if(try1<try2){
  83.               cout << " \n El ganador es " << jug1 << " con " << try1 << " intentos ";
  84.               fprintf(records,"%s con %d puntos gano a %s con %d puntos el ",jug1,10*(MAX-try1),jug2,10*(MAX-try2));
  85.            }
  86.            if(try2<try1){
  87.               cout << " \n El ganador es " << jug2 << " con " << try2 << " intentos ";
  88.               fprintf(records,"%s con %d puntos gano a %s con %d puntos el ",jug2,10*(MAX-try2),jug1,10*(MAX-try1));
  89.            }
  90.            if(try1==try2){
  91.               cout << " \n Empate con " << try1 << " intentos ";
  92.               fprintf(records,"Hubo un empate entre %s y %s a %d puntos el ",jug1,jug2,10*(MAX-try1));
  93.            }
  94.        
  95. // SE APUNTAN LOS RECORDS CON FECHA
  96.            time_t tiempo = time(NULL);
  97.            struct tm *tlocal = localtime(&tiempo);
  98.            char output[128];
  99.            strftime(output,128,"%d/%m/%y a las %H:%M:%S",tlocal);
  100.            fprintf(records,"%s\n",output);
  101.            fclose(records);
  102.        }    
  103.        cout << " \n Volver al menu(1=si)? ";
  104.  
  105.        cin >> retry;
  106.     }while( retry==1 );
  107.     return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement