Untitled
unknown
java
4 years ago
1.7 kB
16
Indexable
import java.util.logging.Level;
import java.util.logging.Logger;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author kevinpg
*/
public class Arbitro {
private int numeroAleatorio;
private boolean acabado = false;
private int turno;
private int numTotalJugadores;
public Arbitro(int numTotalJugadores) {
numeroAleatorio = (int) (Math.random() * 10) + 1;
System.out.println("Número a adivinar: " + numeroAleatorio);
this.turno = 1;
this.numTotalJugadores = numTotalJugadores;
}
public boolean isAcabado() {
return acabado;
}
private void siguienteTurno() {
if (turno == numTotalJugadores) {
turno = 1;
} else {
turno++;
}
System.out.println("\tLe toca a Jug" + turno);
}
public synchronized int getTurno() {
return turno;
}
public synchronized void comprobarNumeroAleatorio(int numero, int id) {
if (id != turno) {
try {
wait();
System.out.println("1");
} catch (InterruptedException ex) {
}
}
if (acabado) {
return;
}
System.out.println("Jugador " + turno + " dice " + numero);
if (numero == numeroAleatorio) {
System.out.println("\tJugador " + turno + " gana, adivinó el número!!!!");
acabado = true;
}
if (!acabado) {
siguienteTurno();
}
notifyAll();
}
}Editor is loading...