-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJuegoAdivinar.java
More file actions
65 lines (54 loc) · 2.21 KB
/
JuegoAdivinar.java
File metadata and controls
65 lines (54 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.util.Scanner;
public class JuegoAdivinar {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int NUM_INT_DEFAULT = 5;
int NUM_MAX_DEFAULT = 10;
boolean salir = false;
int opcion;
int numInt = NUM_INT_DEFAULT;
int numMax = NUM_MAX_DEFAULT;
do{
System.out.println("1. Configurar \n"+
"2. Jugar \n"+
"3. Salir");
System.out.println("Elige una opcion: ");
opcion = sc.nextInt();
switch(opcion){
case 1:
System.out.println("Introduce el numero de intentos: ");
numInt = sc.nextInt();
System.out.println("Introduce el numero maximo de intentos: ");
numMax = sc.nextInt();
break;
case 2:
int numOculto = (int) Math.floor(Math.random()*numMax+1);
int intentosJugador = 1;
int numJugador = 0;
boolean acertado = false;
while(intentosJugador <= numInt && !acertado){
System.out.println("Introduce un numero");
numJugador = sc.nextInt();
if(numJugador == numOculto){
System.out.println("Has ganador. Has necesitado "+intentosJugador+" intentos");
acertado = true;
}else{
if(numJugador > numOculto){
System.out.println("El numero oculto es menor");
}else{
System.out.println("El numero oculto es mayor");
}
System.out.println("Te quedan "+(numInt - intentosJugador)+" intentos.");
intentosJugador++;
}
}
break;
case 3:
salir = true;
break;
default:
break;
}
}while(!salir);
}
}