Aniadido soporte 4 en raya
This commit is contained in:
		
							parent
							
								
									cf9dc54b5c
								
							
						
					
					
						commit
						cb3b2e3882
					
				| @ -1,4 +1,5 @@ | |||||||
| import java.io.BufferedReader; | import java.io.BufferedReader; | ||||||
|  | import java.io.IOException; | ||||||
| import java.io.InputStreamReader; | import java.io.InputStreamReader; | ||||||
| import java.io.OutputStreamWriter; | import java.io.OutputStreamWriter; | ||||||
| import java.io.PrintWriter; | import java.io.PrintWriter; | ||||||
| @ -12,8 +13,6 @@ public class ComunacacionJugador extends Thread{ | |||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	public void run() { | 	public void run() { | ||||||
| 		boolean continuar = true; |  | ||||||
| 		int turno = 2; |  | ||||||
| 		try { | 		try { | ||||||
| 			BufferedReader bufferEntrada = new BufferedReader(new InputStreamReader(this.socket.getInputStream())); | 			BufferedReader bufferEntrada = new BufferedReader(new InputStreamReader(this.socket.getInputStream())); | ||||||
| 			PrintWriter bufferSalida = new PrintWriter(new OutputStreamWriter(this.socket.getOutputStream()),true); | 			PrintWriter bufferSalida = new PrintWriter(new OutputStreamWriter(this.socket.getOutputStream()),true); | ||||||
| @ -21,66 +20,135 @@ public class ComunacacionJugador extends Thread{ | |||||||
| 			int sala = Integer.parseInt(bufferEntrada.readLine())-1; | 			int sala = Integer.parseInt(bufferEntrada.readLine())-1; | ||||||
| 			if(Servidor.addJugador(sala, this.socket)) { | 			if(Servidor.addJugador(sala, this.socket)) { | ||||||
| 				bufferSalida.println("Has entrado en la sala"); | 				bufferSalida.println("Has entrado en la sala"); | ||||||
|  | 				if(Servidor.determinarJuego(sala) == 1) { | ||||||
|  | 					sala -= Servidor.salas3.size(); | ||||||
|  | 					bufferSalida.println("4"); | ||||||
|  | 					partida4(bufferEntrada, bufferSalida, sala); | ||||||
|  | 				}else { | ||||||
|  | 					bufferSalida.println("3"); | ||||||
|  | 					partida3(bufferEntrada, bufferSalida, sala); | ||||||
|  | 				} | ||||||
| 			}else { | 			}else { | ||||||
| 				bufferSalida.println("Error al entrar en la sala"); | 				bufferSalida.println("Error al entrar en la sala"); | ||||||
| 				socket.close(); | 				socket.close(); | ||||||
| 				return; | 				return; | ||||||
| 			} | 			} | ||||||
| 			 | 			 | ||||||
| 			if(Servidor.salas.get(sala).getJugador1().equals(this.socket)) { |  | ||||||
| 				bufferSalida.println("Esperando al segundo jugador"); |  | ||||||
| 				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 (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 (Servidor.salas.get(sala).jugadores[turno%2]) { |  | ||||||
| 					Servidor.salas.get(sala).jugadores[turno%2].notify(); |  | ||||||
| 				} |  | ||||||
| 				synchronized (this.socket) { |  | ||||||
| 					this.socket.wait(); |  | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
| 			while(continuar) { |  | ||||||
| 				int finalJuego = Servidor.salas.get(sala).tablero.finalJuego(); |  | ||||||
| 				if(finalJuego != 0) { |  | ||||||
| 					continuar = false; |  | ||||||
| 					if(finalJuego == turno) { |  | ||||||
| 						bufferSalida.println("v"); |  | ||||||
| 					}else { |  | ||||||
| 						bufferSalida.println("f"); |  | ||||||
| 					} |  | ||||||
| 					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 (Servidor.salas.get(sala).jugadores[turno%2]) { |  | ||||||
| 						Servidor.salas.get(sala).jugadores[turno%2].notify(); |  | ||||||
| 					} |  | ||||||
| 					synchronized (this.socket) { |  | ||||||
| 						this.socket.wait(); |  | ||||||
| 					} |  | ||||||
| 				} |  | ||||||
| 			 | 			 | ||||||
| 			} |  | ||||||
| 			Servidor.salas.remove(sala); |  | ||||||
| 		}catch (Exception e) { | 		}catch (Exception e) { | ||||||
| 			e.printStackTrace(); | 			e.printStackTrace(); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | 	 | ||||||
|  | 	private void partida3(BufferedReader bufferEntrada, PrintWriter bufferSalida, int sala) throws InterruptedException, NumberFormatException, IOException { | ||||||
|  | 		boolean continuar = true; | ||||||
|  | 		int jugador = 2; | ||||||
|  | 		if(Servidor.salas3.get(sala).getJugador1().equals(this.socket)) { | ||||||
|  | 			bufferSalida.println("Esperando al segundo jugador"); | ||||||
|  | 			synchronized (this.socket) { | ||||||
|  | 				this.socket.wait(); | ||||||
|  | 			} | ||||||
|  | 			jugador = 1; | ||||||
|  | 			bufferSalida.println("Primero"); | ||||||
|  | 			bufferSalida.println(Servidor.salas3.get(sala).tablero.getTablero()); | ||||||
|  | 			Servidor.salas3.get(sala).tablero.colocarFicha(Integer.parseInt(bufferEntrada.readLine()),  | ||||||
|  | 					Integer.parseInt(bufferEntrada.readLine()),jugador); | ||||||
|  | 			synchronized (Servidor.salas3.get(sala).jugadores[jugador%2]) { | ||||||
|  | 				Servidor.salas3.get(sala).jugadores[jugador%2].notify(); | ||||||
|  | 			} | ||||||
|  | 			synchronized (this.socket) { | ||||||
|  | 				this.socket.wait(); | ||||||
|  | 			} | ||||||
|  | 		}else { | ||||||
|  | 			bufferSalida.println("Iniciando partida"); | ||||||
|  | 			bufferSalida.println("Segundo"); | ||||||
|  | 			synchronized (Servidor.salas3.get(sala).jugadores[jugador%2]) { | ||||||
|  | 				Servidor.salas3.get(sala).jugadores[jugador%2].notify(); | ||||||
|  | 			} | ||||||
|  | 			synchronized (this.socket) { | ||||||
|  | 				this.socket.wait(); | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 		while(continuar) { | ||||||
|  | 			int finalJuego = Servidor.salas3.get(sala).tablero.finalJuego(); | ||||||
|  | 			if(finalJuego != 0) { | ||||||
|  | 				continuar = false; | ||||||
|  | 				if(finalJuego == jugador) { | ||||||
|  | 					bufferSalida.println("v"); | ||||||
|  | 				}else { | ||||||
|  | 					bufferSalida.println("f"); | ||||||
|  | 				} | ||||||
|  | 				synchronized (Servidor.salas3.get(sala).jugadores[jugador%2]) { | ||||||
|  | 					Servidor.salas3.get(sala).jugadores[jugador%2].notify(); | ||||||
|  | 				} | ||||||
|  | 			}else { | ||||||
|  | 				bufferSalida.println(Servidor.salas3.get(sala).tablero.getTablero()); | ||||||
|  | 				Servidor.salas3.get(sala).tablero.colocarFicha(Integer.parseInt(bufferEntrada.readLine()),  | ||||||
|  | 						Integer.parseInt(bufferEntrada.readLine()),jugador); | ||||||
|  | 				synchronized (Servidor.salas3.get(sala).jugadores[jugador%2]) { | ||||||
|  | 					Servidor.salas3.get(sala).jugadores[jugador%2].notify(); | ||||||
|  | 				} | ||||||
|  | 				synchronized (this.socket) { | ||||||
|  | 					this.socket.wait(); | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 			 | ||||||
|  | 		} | ||||||
|  | 		Servidor.salas3.remove(sala); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	private void partida4(BufferedReader bufferEntrada, PrintWriter bufferSalida, int sala) throws InterruptedException, NumberFormatException, IOException { | ||||||
|  | 		boolean continuar = true; | ||||||
|  | 		int jugador = 2; | ||||||
|  | 		if(Servidor.salas4.get(sala).getJugador1().equals(this.socket)) { | ||||||
|  | 			bufferSalida.println("Esperando al segundo jugador"); | ||||||
|  | 			synchronized (this.socket) { | ||||||
|  | 				this.socket.wait(); | ||||||
|  | 			} | ||||||
|  | 			jugador = 1; | ||||||
|  | 			bufferSalida.println("Primero"); | ||||||
|  | 			bufferSalida.println(Servidor.salas4.get(sala).tablero.getTablero()); | ||||||
|  | 			Servidor.salas4.get(sala).tablero.colocarFicha(Integer.parseInt(bufferEntrada.readLine()),jugador); | ||||||
|  | 			synchronized (Servidor.salas4.get(sala).jugadores[jugador%2]) { | ||||||
|  | 				Servidor.salas4.get(sala).jugadores[jugador%2].notify(); | ||||||
|  | 			} | ||||||
|  | 			synchronized (this.socket) { | ||||||
|  | 				this.socket.wait(); | ||||||
|  | 			} | ||||||
|  | 		}else { | ||||||
|  | 			bufferSalida.println("Iniciando partida"); | ||||||
|  | 			bufferSalida.println("Segundo"); | ||||||
|  | 			synchronized (Servidor.salas4.get(sala).jugadores[jugador%2]) { | ||||||
|  | 				Servidor.salas4.get(sala).jugadores[jugador%2].notify(); | ||||||
|  | 			} | ||||||
|  | 			synchronized (this.socket) { | ||||||
|  | 				this.socket.wait(); | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 		while(continuar) { | ||||||
|  | 			int finalJuego = Servidor.salas4.get(sala).tablero.finalJuego(); | ||||||
|  | 			if(finalJuego != 0) { | ||||||
|  | 				continuar = false; | ||||||
|  | 				if(finalJuego == jugador) { | ||||||
|  | 					bufferSalida.println("v"); | ||||||
|  | 				}else { | ||||||
|  | 					bufferSalida.println("f"); | ||||||
|  | 				} | ||||||
|  | 				synchronized (Servidor.salas4.get(sala).jugadores[jugador%2]) { | ||||||
|  | 					Servidor.salas4.get(sala).jugadores[jugador%2].notify(); | ||||||
|  | 				} | ||||||
|  | 			}else { | ||||||
|  | 				bufferSalida.println(Servidor.salas4.get(sala).tablero.getTablero()); | ||||||
|  | 				Servidor.salas4.get(sala).tablero.colocarFicha(Integer.parseInt(bufferEntrada.readLine()),jugador); | ||||||
|  | 				synchronized (Servidor.salas4.get(sala).jugadores[jugador%2]) { | ||||||
|  | 					Servidor.salas4.get(sala).jugadores[jugador%2].notify(); | ||||||
|  | 				} | ||||||
|  | 				synchronized (this.socket) { | ||||||
|  | 					this.socket.wait(); | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 			 | ||||||
|  | 		} | ||||||
|  | 		Servidor.salas4.remove(sala); | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,14 +1,14 @@ | |||||||
| import java.net.Socket; | import java.net.Socket; | ||||||
| 
 | 
 | ||||||
| public class Sala { | public class Sala3 { | ||||||
| 	int nJugadores; | 	int nJugadores; | ||||||
| 	Socket[] jugadores; | 	Socket[] jugadores; | ||||||
| 	Tablero tablero; | 	Tablero3 tablero; | ||||||
| 	 | 	 | ||||||
| 	public Sala() { | 	public Sala3() { | ||||||
| 		this.nJugadores = 0; | 		this.nJugadores = 0; | ||||||
| 		this.jugadores = new Socket[2]; | 		this.jugadores = new Socket[2]; | ||||||
| 		this.tablero = new Tablero(); | 		this.tablero = new Tablero3(); | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	public boolean aniadirJugador(Socket jugador) { | 	public boolean aniadirJugador(Socket jugador) { | ||||||
| @ -30,7 +30,7 @@ public class Sala { | |||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	public String toString() { | 	public String toString() { | ||||||
| 		return String.valueOf(this.nJugadores); | 		return String.valueOf(this.nJugadores) + "Tres en raya"; | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| } | } | ||||||
							
								
								
									
										36
									
								
								src/Sala4.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								src/Sala4.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,36 @@ | |||||||
|  | import java.net.Socket; | ||||||
|  | 
 | ||||||
|  | public class Sala4 { | ||||||
|  | 	int nJugadores; | ||||||
|  | 	Socket[] jugadores; | ||||||
|  | 	Tablero4 tablero; | ||||||
|  | 	 | ||||||
|  | 	public Sala4() { | ||||||
|  | 		this.nJugadores = 0; | ||||||
|  | 		this.jugadores = new Socket[2]; | ||||||
|  | 		this.tablero = new Tablero4(); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	public boolean aniadirJugador(Socket jugador) { | ||||||
|  | 		if(this.nJugadores <= 1 ) { | ||||||
|  | 			this.jugadores[this.nJugadores] = jugador; | ||||||
|  | 			this.nJugadores++; | ||||||
|  | 			return true; | ||||||
|  | 		}else { | ||||||
|  | 			return false; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	public Socket getJugador1() { | ||||||
|  | 		return this.jugadores[0]; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	public Socket getJugador2() { | ||||||
|  | 		return this.jugadores[1]; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	public String toString() { | ||||||
|  | 		return String.valueOf(this.nJugadores) + "Cuatro en raya"; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | } | ||||||
| @ -5,12 +5,15 @@ import java.util.ArrayList; | |||||||
| 
 | 
 | ||||||
| public class Servidor { | public class Servidor { | ||||||
| 	static Servidor instancia; | 	static Servidor instancia; | ||||||
| 	static ArrayList<Sala> salas; | 	static ArrayList<Sala3> salas3; | ||||||
|  | 	static ArrayList<Sala4> salas4; | ||||||
| 	 | 	 | ||||||
| 	private Servidor() { | 	private Servidor() { | ||||||
| 		ServerSocket server; | 		ServerSocket server; | ||||||
| 		Servidor.salas = new ArrayList<Sala>(); | 		Servidor.salas3 = new ArrayList<Sala3>(); | ||||||
| 		Servidor.salas.add(new Sala()); | 		Servidor.salas3.add(new Sala3()); | ||||||
|  | 		Servidor.salas4 = new ArrayList<Sala4>(); | ||||||
|  | 		Servidor.salas4.add(new Sala4()); | ||||||
| 		try { | 		try { | ||||||
| 			server = new ServerSocket(8080); | 			server = new ServerSocket(8080); | ||||||
| 			while(true) { | 			while(true) { | ||||||
| @ -34,7 +37,11 @@ public class Servidor { | |||||||
| 	public static String mostrarSalas() { | 	public static String mostrarSalas() { | ||||||
| 		String ret = ""; | 		String ret = ""; | ||||||
| 		int cont = 1; | 		int cont = 1; | ||||||
| 		for(Sala sala:Servidor.salas) { | 		for(Sala3 sala:Servidor.salas3) { | ||||||
|  | 			ret += cont + " - Jugadores: " + sala.toString() + "\n"; | ||||||
|  | 			cont++; | ||||||
|  | 		} | ||||||
|  | 		for(Sala4 sala:Servidor.salas4) { | ||||||
| 			ret += cont + " - Jugadores: " + sala.toString() + "\n"; | 			ret += cont + " - Jugadores: " + sala.toString() + "\n"; | ||||||
| 			cont++; | 			cont++; | ||||||
| 		} | 		} | ||||||
| @ -42,10 +49,27 @@ public class Servidor { | |||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	public static boolean addJugador(int sala, Socket socket) { | 	public static boolean addJugador(int sala, Socket socket) { | ||||||
| 		boolean ret = Servidor.salas.get(sala).aniadirJugador(socket); | 		boolean ret = false; | ||||||
| 		if(Servidor.salas.get(sala).nJugadores==1) { | 		if(sala == Servidor.salas3.size()-1) { | ||||||
| 			Servidor.salas.add(new Sala()); | 			ret = Servidor.salas3.get(sala).aniadirJugador(socket); | ||||||
|  | 			if(Servidor.salas3.get(sala).nJugadores==1) { | ||||||
|  | 				Servidor.salas3.add(new Sala3()); | ||||||
|  | 			} | ||||||
|  | 		}else if(sala == (Servidor.salas4.size()+Servidor.salas3.size()-1)) { | ||||||
|  | 			ret = Servidor.salas4.get(sala-Servidor.salas3.size()).aniadirJugador(socket); | ||||||
|  | 			if(Servidor.salas3.get(sala).nJugadores==1) { | ||||||
|  | 				Servidor.salas3.add(new Sala3()); | ||||||
|  | 			} | ||||||
| 		} | 		} | ||||||
|  | 		 | ||||||
| 		return ret; | 		return ret; | ||||||
| 	} | 	} | ||||||
|  | 	 | ||||||
|  | 	public static int determinarJuego(int sala) { | ||||||
|  | 		if(Servidor.salas3.size() > sala) { | ||||||
|  | 			return 0; | ||||||
|  | 		}else { | ||||||
|  | 			return 1; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,8 +1,8 @@ | |||||||
| 
 | 
 | ||||||
| public class Tablero { | public class Tablero3 { | ||||||
| 	int[][] casillas; | 	int[][] casillas; | ||||||
| 	int[] ultimasCoordenadas; | 	int[] ultimasCoordenadas; | ||||||
| 	public Tablero() { | 	public Tablero3() { | ||||||
| 		this.casillas = new int[3][3]; | 		this.casillas = new int[3][3]; | ||||||
| 		this.ultimasCoordenadas = new int[2]; | 		this.ultimasCoordenadas = new int[2]; | ||||||
| 	} | 	} | ||||||
							
								
								
									
										118
									
								
								src/Tablero4.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										118
									
								
								src/Tablero4.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,118 @@ | |||||||
|  | 
 | ||||||
|  | public class Tablero4 { | ||||||
|  | 	int[][] casillas; | ||||||
|  | 	int[] ultimasCoordenadas; | ||||||
|  | 	public Tablero4() { | ||||||
|  | 		this.casillas = new int[7][6]; | ||||||
|  | 		this.ultimasCoordenadas = new int[2]; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	public boolean colocarFicha(int x, int jugador) { | ||||||
|  | 		if(this.casillas[x][6] == 0) { | ||||||
|  | 			for(int i = 0;i < this.casillas[x].length; i++) { | ||||||
|  | 				if(this.casillas[x][i] == 0) { | ||||||
|  | 					this.casillas[x][i] = jugador; | ||||||
|  | 					this.ultimasCoordenadas[0]=x; | ||||||
|  | 					this.ultimasCoordenadas[1]=i; | ||||||
|  | 					break; | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 			return true; | ||||||
|  | 		} | ||||||
|  | 		return false;	 | ||||||
|  | 		 | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	public int getLastX() { | ||||||
|  | 		return this.ultimasCoordenadas[0]; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	public int getLastY() { | ||||||
|  | 		return this.ultimasCoordenadas[1]; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	public String getTablero() { | ||||||
|  | 		String ret = ""; | ||||||
|  | 		for(int i = 0; i< this.casillas.length; i++) { | ||||||
|  | 			for(int j = 0; j < this.casillas[i].length; j++) { | ||||||
|  | 				ret += this.casillas[i][j] + " "; | ||||||
|  | 			} | ||||||
|  | 			if(i != this.casillas.length-1) { | ||||||
|  | 				ret += "\n"; | ||||||
|  | 			} | ||||||
|  | 			 | ||||||
|  | 		} | ||||||
|  | 		return ret; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	public int finalJuego() { | ||||||
|  |         int ret=0; | ||||||
|  |         for(int i = 0;i < this.casillas.length-1; i++) { | ||||||
|  | 			for(int j = 0;j < this.casillas[i].length; j++) { | ||||||
|  | 				if(comprobarHorizontal(i, j, this.casillas[i][j]) <= 4) { | ||||||
|  | 					return this.casillas[i][j]; | ||||||
|  | 				} | ||||||
|  | 				if(comprobarVertical(i, j, this.casillas[i][j]) <= 4) { | ||||||
|  | 					return this.casillas[i][j]; | ||||||
|  | 				} | ||||||
|  | 				if(comprobarDiagonalArriba(i, j, this.casillas[i][j]) <= 4) { | ||||||
|  | 					return this.casillas[i][j]; | ||||||
|  | 				} | ||||||
|  | 				if(comprobarDiagonalAbajo(i, j, this.casillas[i][j]) <= 4) { | ||||||
|  | 					return this.casillas[i][j]; | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  |         return ret; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	private int comprobarHorizontal(int x, int y, int jugador) { | ||||||
|  | 		if(x == this.casillas.length-1) { | ||||||
|  | 			return 0; | ||||||
|  | 		} | ||||||
|  | 		if(this.casillas[x+1][y] == jugador) { | ||||||
|  | 			return comprobarHorizontal(x+1, y, jugador)+1; | ||||||
|  | 		}else { | ||||||
|  | 			return 0; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	private int comprobarVertical(int x, int y, int jugador) { | ||||||
|  | 		if(y == this.casillas[x].length-1) { | ||||||
|  | 			return 0; | ||||||
|  | 		} | ||||||
|  | 		if(this.casillas[x][y+1] == jugador) { | ||||||
|  | 			return comprobarVertical(x, y+1, jugador)+1; | ||||||
|  | 		}else { | ||||||
|  | 			return 0; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	private int comprobarDiagonalArriba(int x, int y, int jugador) { | ||||||
|  | 		if(y == this.casillas[x].length-1) { | ||||||
|  | 			return 0; | ||||||
|  | 		} | ||||||
|  | 		if(x == this.casillas.length-1) { | ||||||
|  | 			return 0; | ||||||
|  | 		} | ||||||
|  | 		if(this.casillas[x][y+1] == jugador) { | ||||||
|  | 			return comprobarDiagonalArriba(x+1, y+1, jugador)+1; | ||||||
|  | 		}else { | ||||||
|  | 			return 0; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	private int comprobarDiagonalAbajo(int x, int y, int jugador) { | ||||||
|  | 		if(y == 0) { | ||||||
|  | 			return 0; | ||||||
|  | 		} | ||||||
|  | 		if(x == this.casillas.length-1) { | ||||||
|  | 			return 0; | ||||||
|  | 		} | ||||||
|  | 		if(this.casillas[x][y+1] == jugador) { | ||||||
|  | 			return comprobarDiagonalAbajo(x+1, y-1, jugador)+1; | ||||||
|  | 		}else { | ||||||
|  | 			return 0; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user