View difference between Paste ID: V6WUQqqv and MEd836Kf
SHOW: | | - or go back to the newest paste.
1
#include <stdio.h> // Contiene getpid (Obtener procesos)
2
#include <stdlib.h> // Contiene rand y srand
3
#include <time.h> // Contiene time, localtime y strftime
4
5
#define RANGO 100
6
#define VIDAS 9
7
8
int patata( int trial, int jug, int num ){
9
    int v;
10
    
11
    srand(time(NULL)); // Si se usa como recurso aleatorio el getpid()
12
                       // Da todo el rato el mismo numero
13
    if( jug == 1 ) num = (rand()%RANGO)+1;
14
15-
       if( v==0 ) printf(" \n Has fallado, lo siento ");
15+
16
       scanf("%d",&trial);
17
       if( num<trial && v!=0 ) printf(" Menor que %d (Intentos restantes: %d) ",trial,v);
18
       if( num>trial && v!=0 ) printf(" Mayor que %d (Intentos restantes: %d) ",trial,v);
19
       if( v==0 && num!=trial ) printf(" \n Has fallado, lo siento ");
20
    }
21
    if( num==trial )printf(" \n Correcto! Era %d ",num);
22
    return v;
23
}
24
25
int main(){
26
    FILE *records=fopen("Records patata caliente (2J).txt","a");
27
    int jug, v1, v2, num, trial=0, retry;
28
    char jug1[4], jug2[4];
29
    
30
    do{
31-
       if( jug==0 ) return 0;
31+
32
          system("cls");
33
          printf(" \n -= La patata caliente =- \n 1 o 2 Jugadores? ");
34
          scanf("%d",&jug);
35
       }while( jug!=1 && jug!=2 && jug!=0 );
36-
          srand(getpid());
36+
       if( jug==0 ) return 0; // Salida desde el menu
37-
          num = (rand()%RANGO)+1;
37+
38
// MODO: UN JUGADOR
39
       if( jug==1 ){
40
          printf(" \n Averigua que numero estoy pensando entre 0 y 100: ");
41
          patata(trial,jug,num);
42
          }
43-
// INICIALES PRIMER JUGADOR
43+
44
// MODO: DOS JUGADORES
45
       if( jug==2 ){
46-
// INCIALES SEGUNDO JUGADOR
46+
47
// INICIALES JUGADORES
48
           printf(" \n Jugador 1, introduce tus iniciales: ");
49
           scanf("%s",jug1);
50
           printf(" \n Jugador 2, introduce tus iniciales: ");
51
           scanf("%s",jug2);
52-
              printf(" \n -= Turno del jugador 1 =- ");
52+
53-
              printf(" \n Jugador 2, introduce un numero del 1 al %d cuando jugador 1 no mire: ",RANGO);
53+
54
           do{
55
              system("cls");
56
              printf(" \n -= Turno de %s =- ",jug1);
57-
           printf(" \n Bien, adivina el numero, jugador 1: ");
57+
              printf(" \n %s, introduce un numero del 1 al %d cuando %s no mire: ",jug2,RANGO,jug1);
58
              scanf("%d",&num);
59
           }while( num<1 || num>RANGO );
60
           system("cls");
61
           printf(" \n Bien, adivina el numero, %s: ",jug1);
62
           v1=patata(trial,jug,num);
63
           system("PAUSE");
64-
              printf(" \n -= Turno del jugador 2 =- ");
64+
65-
              printf(" \n Jugador 1, introduce un numero del 1 al %d cuando jugador 2 no mire: ",RANGO);
65+
66
           do{
67
              system("cls");
68
              printf(" \n -= Turno del %s =- ",jug2);
69-
           printf(" \n Bien, adivina el numero, jugador 2: ");
69+
              printf(" \n %s, introduce un numero del 1 al %d cuando %s no mire: ",jug1,RANGO,jug2);
70
              scanf("%d",&num);
71
           }while( num<1 || num>RANGO );
72
           system("cls");
73
           printf(" \n Bien, adivina el numero, %s: ",jug2);
74
           v2=patata(trial,jug,num);
75
           system("PAUSE");
76-
              printf(" \n El ganador es el jugador 1 con %d intentos ",VIDAS-v1);
76+
77-
              fprintf(records,"J1 con %d puntos gano a J2 con %d puntos el ",10*v1,10*v2);
77+
78
           system("cls");
79
           if(v1>v2){
80-
              printf(" \n El ganador es el jugador 2 con %d intentos ",VIDAS-v2);
80+
              printf(" \n El ganador es %s con %d intentos ",jug1,VIDAS-v1);
81-
              fprintf(records,"J2 con %d puntos gano a J1 con %d puntos el ",10*v2,10*v1);
81+
              fprintf(records,"%s con %d puntos gano a %s con %d puntos el ",jug1,10*v1,jug2,10*v2);
82
           }
83
           if(v2>v1){
84
              printf(" \n El ganador es %s con %d intentos ",jug2,VIDAS-v2);
85-
              fprintf(records,"Hubo un empate entre J1 Y J2 a %d puntos el ",10*v1);
85+
              fprintf(records,"%s con %d puntos gano a %s con %d puntos el ",jug2,10*v2,jug1,10*v1);
86
           }
87
           if(v1==v2){
88-
// SE APUNTAN LOS RECORDS CON FECHA FECHA
88+
89
              fprintf(records,"Hubo un empate entre %s Y %s a %d puntos el ",jug1,jug2,10*v1);
90
           }
91
       
92
// SE APUNTAN LOS RECORDS CON FECHA
93
           time_t tiempo = time(NULL);
94
           struct tm *tlocal = localtime(&tiempo);
95
           char output[128];
96
           strftime(output,128,"%d/%m/%y a las %H:%M:%S",tlocal);
97
           fprintf(records,"%s\n",output);
98
           fclose(records);
99
       }    
100
       printf(" \n Volver al menu(1=si)? ");
101
102
       scanf("%d",&retry);
103
    }while( retry==1 );
104
    return 0;
105
}