Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class muertos
- {
- static Scanner t = new Scanner(System.in);
- public static void main( String [] args ){
- System.out.println("\n Bienvenido al juego de Muertos y heridos\n");
- System.out.println(" Tienes que adivinar un numero entre 0000 y 9999.");
- System.out.println(" Prueba numeros y como pista recibiras 1 herido por cada cifra acertada.");
- System.out.println(" Si aciertas tambien su posicion, en vez de un herido, recibiras 1 muerto.");
- System.out.println(" Ganas cuando consigas 4 muertos, es decir, cuando ordenes los 4 numeros");
- int n1 = (int) (Math.random()*10);
- int n2 = (int) (Math.random()*10);
- int n3 = (int) (Math.random()*10);
- int n4 = (int) (Math.random()*10);
- int n = (int) (n1*1000+n2*100+n3*10+n4);
- int intentos=0;
- System.out.print(" Adivina que numero estoy pensando (0000-9999)"+n+": ");
- int g = t.nextInt();
- Calendar cal = Calendar.getInstance();
- long ti = cal.getTimeInMillis();
- boolean correcto=false;
- while( !correcto ){
- int heridos=0;
- int muertos=0;
- int g1 = g/1000;
- if (g1==n1) muertos++;
- else if (g1==n2 || g1==n3 || g1==n4) heridos++;
- int g2=g/100-g1*10;
- if (g2==n2) muertos++;
- else if (g2==n1 || g2==n3 || g2==n4) heridos++;
- int g3=g/10-g1*100-g2*10;
- if (g3==n3) muertos++;
- else if (g3==n1 || g3==n2 || g3==n4) heridos++;
- int g4=g-g1*1000-g2*100-g3*10;
- if (g4==n4) muertos++;
- else if (g4==n1 || g4==n2 || g3==n3) heridos++;
- if (muertos==4) correcto=true;
- else {
- System.out.print(" En "+g1+""+g2+""+g3+""+g4+" hay "+muertos+" muertos y "+heridos+" heridos. Sigue intentandolo: ");
- g=t.nextInt();
- }
- intentos++;
- }
- Calendar cal2 = Calendar.getInstance();
- long tf=cal2.getTimeInMillis();
- double dif = (tf-ti)/1000.0;
- int puntuacion = (int) ((1.0/intentos + 1.0/(dif+Math.pow(10,10)))*1000);
- System.out.println("Has acertado. Intentos: "+intentos+". Tiempo: "+dif+". Puntos: "+puntuacion);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement