Arreglados errores menores

This commit is contained in:
Guillermo Roche 2019-12-14 23:32:38 +01:00
parent 2b3212d7df
commit 324a4db7fe
2 changed files with 52 additions and 18 deletions

View File

@ -12,7 +12,12 @@ public class Main {
System.out.println("Entra cliente"); System.out.println("Entra cliente");
Socket socket; Socket socket;
try { try {
if(args.length>0) {
socket = new Socket(args[0], 8080);
}else {
socket = new Socket("localhost", 8080); socket = new Socket("localhost", 8080);
}
Scanner es = new Scanner(System.in); Scanner es = new Scanner(System.in);
BufferedReader bufferEntrada = new BufferedReader(new InputStreamReader(socket.getInputStream())); BufferedReader bufferEntrada = new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter bufferSalida = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()),true); PrintWriter bufferSalida = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()),true);
@ -24,13 +29,14 @@ public class Main {
System.out.println("Introduce el numero de partida en el que quieres entrar"); System.out.println("Introduce el numero de partida en el que quieres entrar");
bufferSalida.println(es.nextLine()); bufferSalida.println(es.nextLine());
System.out.println(bufferEntrada.readLine()); System.out.println(bufferEntrada.readLine());
System.out.println(bufferEntrada.readLine()); String tipoJuego = bufferEntrada.readLine();
System.out.println(bufferEntrada.readLine()); switch(tipoJuego) {
while(dibujarTablero(bufferEntrada)) { case "3":
System.out.println("introduce la x de la nueva marca"); partida3(bufferEntrada, bufferSalida, es);
bufferSalida.println(es.nextLine()); break;
System.out.println("introduce la y de la nueva marca"); case "4":
bufferSalida.println(es.nextLine()); partida4(bufferEntrada, bufferSalida, es);
break;
} }
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
@ -38,7 +44,27 @@ public class Main {
} }
} }
static boolean dibujarTablero(BufferedReader entrada) throws IOException { static void partida3(BufferedReader bufferEntrada, PrintWriter bufferSalida, Scanner es) throws IOException {
System.out.println(bufferEntrada.readLine());
System.out.println(bufferEntrada.readLine());
while(dibujarTablero3(bufferEntrada)) {
System.out.println("introduce la x de la nueva marca");
bufferSalida.println(es.nextLine());
System.out.println("introduce la y de la nueva marca");
bufferSalida.println(es.nextLine());
}
}
static void partida4(BufferedReader bufferEntrada, PrintWriter bufferSalida, Scanner es) throws IOException {
System.out.println(bufferEntrada.readLine());
System.out.println(bufferEntrada.readLine());
while(dibujarTablero4(bufferEntrada)) {
System.out.println("introduce la columna de la nueva ficha");
bufferSalida.println(es.nextLine());
}
}
static boolean dibujarTablero3(BufferedReader entrada) throws IOException {
for(int i = 0; i < 3; i++) { for(int i = 0; i < 3; i++) {
String linea = entrada.readLine(); String linea = entrada.readLine();
if(linea.length() == 1) { if(linea.length() == 1) {
@ -55,4 +81,21 @@ public class Main {
return true; return true;
} }
static boolean dibujarTablero4(BufferedReader entrada) throws IOException {
for(int i = 0; i < 7; i++) {
String linea = entrada.readLine();
if(linea.length() == 1) {
if(linea.equals("v")) {
System.out.println("Has ganado!");
}else {
System.out.println("Has perdido...");
}
return false;
} else {
System.out.println(linea);
}
}
return true;
}
} }

View File

@ -1,9 +0,0 @@
public class Tablero {
int[][] tablero;
public Tablero() {
// TODO Auto-generated constructor stub
}
}