From 5e4545cbfb554c987823bc4d5cb932662f80bf12 Mon Sep 17 00:00:00 2001 From: Guillermo Date: Thu, 12 Dec 2019 21:23:38 +0100 Subject: [PATCH] Arreglado distintos clientes --- src/ComunacacionJugador.java | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/ComunacacionJugador.java b/src/ComunacacionJugador.java index d96643a..ba61bad 100644 --- a/src/ComunacacionJugador.java +++ b/src/ComunacacionJugador.java @@ -29,24 +29,28 @@ public class ComunacacionJugador extends Thread{ if(Servidor.salas.get(sala).getJugador1().equals(this.socket)) { bufferSalida.println("Esperando al segundo jugador"); - synchronized (getClass()) { - this.getClass().wait(); + synchronized (this.socket) { + this.socket.wait(); } turno = 1; bufferSalida.println("Primero"); bufferSalida.println(Servidor.salas.get(sala).tablero.getTablero()); Servidor.salas.get(sala).tablero.colocarFicha(Integer.parseInt(bufferEntrada.readLine()), Integer.parseInt(bufferEntrada.readLine()),turno); - synchronized (getClass()) { - this.getClass().notifyAll(); - this.getClass().wait(); + synchronized (Servidor.salas.get(sala).jugadores[turno%2]) { + Servidor.salas.get(sala).jugadores[turno%2].notify(); + } + synchronized (this.socket) { + this.socket.wait(); } }else { bufferSalida.println("Iniciando partida"); bufferSalida.println("Segundo"); - synchronized (getClass()) { - this.getClass().notifyAll(); - this.getClass().wait(); + synchronized (Servidor.salas.get(sala).jugadores[turno%2]) { + Servidor.salas.get(sala).jugadores[turno%2].notify(); + } + synchronized (this.socket) { + this.socket.wait(); } } while(continuar) { @@ -58,16 +62,18 @@ public class ComunacacionJugador extends Thread{ }else { bufferSalida.println("f"); } - synchronized (getClass()) { - this.getClass().notifyAll(); + synchronized (Servidor.salas.get(sala).jugadores[turno%2]) { + Servidor.salas.get(sala).jugadores[turno%2].notify(); } }else { bufferSalida.println(Servidor.salas.get(sala).tablero.getTablero()); Servidor.salas.get(sala).tablero.colocarFicha(Integer.parseInt(bufferEntrada.readLine()), Integer.parseInt(bufferEntrada.readLine()),turno); - synchronized (getClass()) { - this.getClass().notifyAll(); - this.getClass().wait(); + synchronized (Servidor.salas.get(sala).jugadores[turno%2]) { + Servidor.salas.get(sala).jugadores[turno%2].notify(); + } + synchronized (this.socket) { + this.socket.wait(); } }