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");
Socket socket;
try {
socket = new Socket("localhost", 8080);
if(args.length>0) {
socket = new Socket(args[0], 8080);
}else {
socket = new Socket("localhost", 8080);
}
Scanner es = new Scanner(System.in);
BufferedReader bufferEntrada = new BufferedReader(new InputStreamReader(socket.getInputStream()));
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");
bufferSalida.println(es.nextLine());
System.out.println(bufferEntrada.readLine());
System.out.println(bufferEntrada.readLine());
System.out.println(bufferEntrada.readLine());
while(dibujarTablero(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());
String tipoJuego = bufferEntrada.readLine();
switch(tipoJuego) {
case "3":
partida3(bufferEntrada, bufferSalida, es);
break;
case "4":
partida4(bufferEntrada, bufferSalida, es);
break;
}
} catch (IOException e) {
// 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++) {
String linea = entrada.readLine();
if(linea.length() == 1) {
@ -54,5 +80,22 @@ public class Main {
}
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
}
}