Hasta JSON
This commit is contained in:
		
							parent
							
								
									324a4db7fe
								
							
						
					
					
						commit
						bd2d28cc04
					
				| @ -2,5 +2,8 @@ | ||||
| <classpath> | ||||
| 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> | ||||
| 	<classpathentry kind="src" path="src"/> | ||||
| 	<classpathentry kind="lib" path="gson-2.8.6-javadoc.jar"/> | ||||
| 	<classpathentry kind="lib" path="gson-2.8.6-sources.jar"/> | ||||
| 	<classpathentry kind="lib" path="gson-2.8.6.jar"/> | ||||
| 	<classpathentry kind="output" path="bin"/> | ||||
| </classpath> | ||||
|  | ||||
							
								
								
									
										2
									
								
								.project
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								.project
									
									
									
									
									
								
							| @ -1,6 +1,6 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <projectDescription> | ||||
| 	<name>Cliente2</name> | ||||
| 	<name>Cliente2Json</name> | ||||
| 	<comment></comment> | ||||
| 	<projects> | ||||
| 	</projects> | ||||
|  | ||||
							
								
								
									
										
											BIN
										
									
								
								gson-2.8.6-javadoc.jar
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								gson-2.8.6-javadoc.jar
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								gson-2.8.6-sources.jar
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								gson-2.8.6-sources.jar
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								gson-2.8.6.jar
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								gson-2.8.6.jar
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -6,11 +6,14 @@ import java.io.PrintWriter; | ||||
| import java.net.Socket; | ||||
| import java.util.Scanner; | ||||
| 
 | ||||
| import com.google.gson.Gson; | ||||
| 
 | ||||
| public class Main { | ||||
| 
 | ||||
| 	public static void main(String[] args) { | ||||
| 		System.out.println("Entra cliente"); | ||||
| 		Socket socket; | ||||
| 		Gson gson = new Gson(); | ||||
| 		try { | ||||
| 			if(args.length>0) { | ||||
| 				socket = new Socket(args[0], 8080); | ||||
| @ -21,15 +24,13 @@ public class Main { | ||||
| 			Scanner es = new Scanner(System.in); | ||||
| 			BufferedReader bufferEntrada = new BufferedReader(new InputStreamReader(socket.getInputStream())); | ||||
| 			PrintWriter bufferSalida = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()),true); | ||||
| 			String entrada = bufferEntrada.readLine(); | ||||
| 			while(!entrada.equals("fin")) { | ||||
| 			String entrada = gson.fromJson(bufferEntrada.readLine(), String.class); | ||||
| 			System.out.println(entrada); | ||||
| 				entrada = bufferEntrada.readLine(); | ||||
| 			} | ||||
| 			 | ||||
| 			System.out.println("Introduce el numero de partida en el que quieres entrar"); | ||||
| 			bufferSalida.println(es.nextLine()); | ||||
| 			System.out.println(bufferEntrada.readLine()); | ||||
| 			String tipoJuego = bufferEntrada.readLine(); | ||||
| 			System.out.println(gson.fromJson(bufferEntrada.readLine(), String.class)); | ||||
| 			String tipoJuego = gson.fromJson(bufferEntrada.readLine(), String.class); | ||||
| 			switch(tipoJuego) { | ||||
| 			case "3": | ||||
| 				partida3(bufferEntrada, bufferSalida, es); | ||||
| @ -45,9 +46,10 @@ public class Main { | ||||
| 	} | ||||
| 	 | ||||
| 	static void partida3(BufferedReader bufferEntrada, PrintWriter bufferSalida, Scanner es) throws IOException { | ||||
| 		System.out.println(bufferEntrada.readLine()); | ||||
| 		System.out.println(bufferEntrada.readLine()); | ||||
| 		while(dibujarTablero3(bufferEntrada)) { | ||||
| 		Gson gson = new Gson(); | ||||
| 		System.out.println(gson.fromJson(bufferEntrada.readLine(), String.class)); | ||||
| 		System.out.println(gson.fromJson(bufferEntrada.readLine(), String.class)); | ||||
| 		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"); | ||||
| @ -56,46 +58,27 @@ public class Main { | ||||
| 	} | ||||
| 	 | ||||
| 	static void partida4(BufferedReader bufferEntrada, PrintWriter bufferSalida, Scanner es) throws IOException { | ||||
| 		System.out.println(bufferEntrada.readLine()); | ||||
| 		System.out.println(bufferEntrada.readLine()); | ||||
| 		while(dibujarTablero4(bufferEntrada)) { | ||||
| 		Gson gson = new Gson(); | ||||
| 		System.out.println(gson.fromJson(bufferEntrada.readLine(), String.class)); | ||||
| 		System.out.println(gson.fromJson(bufferEntrada.readLine(), String.class)); | ||||
| 		while(dibujarTablero(bufferEntrada)) { | ||||
| 			System.out.println("introduce la columna de la nueva ficha"); | ||||
| 			bufferSalida.println(es.nextLine()); | ||||
| 			bufferSalida.println(gson.fromJson(es.nextLine(), String.class)); | ||||
| 		} | ||||
| 	} | ||||
| 	 | ||||
| 	static boolean dibujarTablero3(BufferedReader entrada) throws IOException { | ||||
| 		for(int i = 0; i < 3; i++) { | ||||
| 			String linea = entrada.readLine(); | ||||
| 			if(linea.length() == 1) { | ||||
| 				if(linea.equals("v")) { | ||||
| 	static boolean dibujarTablero(BufferedReader entrada) throws IOException { | ||||
| 		Gson gson = new Gson(); | ||||
| 		String linea = gson.fromJson(entrada.readLine(), String.class); | ||||
| 		if(linea.contains("v")) { | ||||
| 			System.out.println("Has ganado!"); | ||||
| 				}else { | ||||
| 		}else if (linea.contains("f")){ | ||||
| 			System.out.println("Has perdido..."); | ||||
| 				} | ||||
| 				return false; | ||||
| 			} else { | ||||
| 		}else { | ||||
| 			System.out.println(linea); | ||||
| 			} | ||||
| 		} | ||||
| 			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; | ||||
| 	} | ||||
| 	 | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user