Advertisement
Kyrexar

Muertos

May 1st, 2013
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.41 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class muertos
  4. {
  5.     static Scanner t = new Scanner(System.in);
  6.  
  7.     public static void main( String [] args ){
  8.         System.out.println("\n Bienvenido al juego de Muertos y heridos\n");
  9.         System.out.println(" Tienes que adivinar un numero entre 0000 y 9999.");
  10.         System.out.println(" Prueba numeros y como pista recibiras 1 herido por cada cifra acertada.");
  11.         System.out.println(" Si aciertas tambien su posicion, en vez de un herido, recibiras 1 muerto.");
  12.         System.out.println(" Ganas cuando consigas 4 muertos, es  decir, cuando ordenes los 4 numeros");
  13.        
  14.         int n1 = (int) (Math.random()*10);
  15.         int n2 = (int) (Math.random()*10);
  16.         int n3 = (int) (Math.random()*10);
  17.         int n4 = (int) (Math.random()*10);
  18.         int n = (int) (n1*1000+n2*100+n3*10+n4);
  19.        
  20.         int intentos=0;
  21.        
  22.         System.out.print(" Adivina que numero estoy pensando (0000-9999)"+n+": ");
  23.         int g = t.nextInt();
  24.        
  25.         Calendar cal = Calendar.getInstance();
  26.         long ti = cal.getTimeInMillis();
  27.        
  28.         boolean correcto=false;
  29.         while( !correcto ){
  30.             int heridos=0;
  31.             int muertos=0;
  32.            
  33.             int g1 = g/1000;
  34.             if (g1==n1) muertos++;
  35.             else if (g1==n2 || g1==n3 || g1==n4) heridos++;
  36.            
  37.             int g2=g/100-g1*10;
  38.             if (g2==n2) muertos++;
  39.             else if (g2==n1 || g2==n3 || g2==n4) heridos++;
  40.            
  41.             int g3=g/10-g1*100-g2*10;
  42.             if (g3==n3) muertos++;
  43.             else if (g3==n1 || g3==n2 || g3==n4) heridos++;
  44.            
  45.             int g4=g-g1*1000-g2*100-g3*10;
  46.             if (g4==n4) muertos++;
  47.             else if (g4==n1 || g4==n2 || g3==n3) heridos++;
  48.            
  49.             if (muertos==4) correcto=true;
  50.             else {
  51.                 System.out.print(" En "+g1+""+g2+""+g3+""+g4+" hay "+muertos+" muertos y "+heridos+" heridos. Sigue intentandolo: ");
  52.                 g=t.nextInt();
  53.             }
  54.             intentos++;
  55.         }
  56.         Calendar cal2 = Calendar.getInstance();
  57.         long tf=cal2.getTimeInMillis();
  58.         double dif = (tf-ti)/1000.0;
  59.         int puntuacion = (int) ((1.0/intentos + 1.0/(dif+Math.pow(10,10)))*1000);
  60.        
  61.         System.out.println("Has acertado. Intentos: "+intentos+". Tiempo: "+dif+". Puntos: "+puntuacion);
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement