Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h> // Contiene getpid (Obtener procesos)
- #include <stdlib.h> // Contiene rand y srand
- #include <time.h> // Contiene time, localtime y strftime
- #define RANGO 100
- #define VIDAS 9
- int patata( int trial, int jug, int num ){
- int v;
- for( v=VIDAS ; (v>=0 && num!=trial) ; v-- ){
- scanf("%d",&trial);
- if( num<trial && v!=0 ) printf(" Menor que %d (Intentos restantes: %d) ",trial,v);
- if( num>trial && v!=0 ) printf(" Mayor que %d (Intentos restantes: %d) ",trial,v);
- if( v==0 ) printf(" \n Has fallado, lo siento ");
- }
- if( num==trial )printf(" \n Correcto! Era %d ",num);
- return v;
- }
- int main(){
- FILE *records=fopen("Records patata caliente (2J).txt","a");
- int jug, v1, v2, num, trial=0, retry;
- do{
- do{
- system("cls");
- printf(" \n -= La patata caliente =- \n 1 o 2 Jugadores? ");
- scanf("%d",&jug);
- }while( jug!=1 && jug!=2 && jug!=0 );
- if( jug==0 ) return 0;
- // MODO: UN JUGADOR
- if( jug==1 ){
- printf(" \n Averigua que numero estoy pensando entre 0 y 100: ");
- srand(getpid());
- num = (rand()%RANGO)+1;
- patata(trial,jug,num);
- }
- // MODO: DOS JUGADORES
- if( jug==2 ){
- // INICIALES PRIMER JUGADOR
- // INCIALES SEGUNDO JUGADOR
- // JUGADOR 1 JUEGA
- do{
- system("cls");
- printf(" \n -= Turno del jugador 1 =- ");
- printf(" \n Jugador 2, introduce un numero del 1 al %d cuando jugador 1 no mire: ",RANGO);
- scanf("%d",&num);
- }while( num<1 || num>RANGO );
- system("cls");
- printf(" \n Bien, adivina el numero, jugador 1: ");
- v1=patata(trial,jug,num);
- system("PAUSE");
- // JUGADOR 2 JUEGA
- do{
- system("cls");
- printf(" \n -= Turno del jugador 2 =- ");
- printf(" \n Jugador 1, introduce un numero del 1 al %d cuando jugador 2 no mire: ",RANGO);
- scanf("%d",&num);
- }while( num<1 || num>RANGO );
- system("cls");
- printf(" \n Bien, adivina el numero, jugador 2: ");
- v2=patata(trial,jug,num);
- system("PAUSE");
- // RESULTADOS
- system("cls");
- if(v1>v2){
- printf(" \n El ganador es el jugador 1 con %d intentos ",VIDAS-v1);
- fprintf(records,"J1 con %d puntos gano a J2 con %d puntos el ",10*v1,10*v2);
- }
- if(v2>v1){
- printf(" \n El ganador es el jugador 2 con %d intentos ",VIDAS-v2);
- fprintf(records,"J2 con %d puntos gano a J1 con %d puntos el ",10*v2,10*v1);
- }
- if(v1==v2){
- printf(" \n Empate con %d intentos ",VIDAS-v1);
- fprintf(records,"Hubo un empate entre J1 Y J2 a %d puntos el ",10*v1);
- }
- // SE APUNTAN LOS RECORDS CON FECHA 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);
- }
- printf(" \n Volver al menu(1=si)? ");
- scanf("%d",&retry);
- }while( retry==1 );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement