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
- #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(){
- 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;
- if( jug==1 ){ // MODO: UN JUGADOR
- printf(" \n Averigua que numero estoy pensando entre 0 y 100: ");
- srand(getpid());
- num = (rand()%RANGO)+1;
- patata(trial,jug,num);
- }
- if( jug==2 ){ // MODO: DOS JUGADORES
- 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");
- 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");
- system("cls");
- if(v1>v2) printf(" \n El ganador es el jugador 1 con %d intentos ",VIDAS-v1);
- if(v2>v1) printf(" \n El ganador es el jugador 2 con %d intentos ",VIDAS-v2);
- if(v1==v2) printf(" \n Empate con %d intentos ",RANGO-v1);
- }
- printf(" \n Volver al menu(1=si)? ");
- scanf("%d",&retry);
- }while( retry==1 );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment