elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Recopilación Tutoriales y Manuales Hacking, Seguridad, Privacidad, Hardware, etc


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  Java
| | | |-+  Haciendo Sopa de Letras
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Haciendo Sopa de Letras  (Leído 3,614 veces)
ITenZangetsuB

Desconectado Desconectado

Mensajes: 2


Ver Perfil
Haciendo Sopa de Letras
« en: 28 Octubre 2017, 14:04 pm »

A ver estoy intentando hacer una Sopa de letras.

Y tengo algunas dudas  la primera no consigo que lo que tengo en el fichero sopa.data se imprima en la consola estado realizando varias pruebas para intentarlo y nada.

Se tambien que tengo que hacer una clase Position para que me pase por consola la palabra en determinada posicion.

Se me  puedes echar algún cable lo agradeceria porque estado intentando pruebas y buscando por internet ejemplos que me ayudaran Gracias de todas formas.

Código
  1. public class SopaFileHunder {
  2.  
  3. protected char sopa[][];
  4. private int punt=0;
  5. private int maximo;
  6.  
  7. public SopaFileHunder(int largo,int ancho){
  8. this.maximo=largo;
  9. sopa=new char[largo][ancho];
  10.  
  11. }
  12.  
  13. public void Cargar(String cargar) {
  14. (new FileInputStream(cargar)))){
  15. Object[] lines = car.lines().toArray();
  16.  
  17. if(lines.length>0) {
  18. sopa= new char[lines.length][((String)lines[0]).length()];
  19.  
  20. for (int i = 0; i < lines.length; i++) {
  21. sopa[i]=((String)lines[i]).toCharArray();
  22. }
  23. }
  24.  
  25. } catch (FileNotFoundException e) {
  26. // TODO Auto-generated catch block
  27. e.printStackTrace();
  28. } catch (IOException e) {
  29. // TODO Auto-generated catch block
  30. e.printStackTrace();
  31. }
  32.  
  33.  
  34.  
  35.  
  36. /* if(punt!=maximo) {
  37. sopa[punt]=cargar.toCharArray();
  38. punt++;
  39. }
  40. */
  41.  
  42. }
  43.  
  44.  
  45. public char getChar(int fila, int col) {
  46. return sopa[fila][col];
  47.  
  48. }
  49.  
  50. public String getRow(int posicion) {
  51. String sor="";
  52. for (int i = 0; i < sopa[posicion].length; i++) {
  53. sor=sor+sopa[posicion][i];
  54. }
  55.  
  56. return sor;
  57.  
  58. }
  59.  
  60. public String getCol(int posicion) {
  61. String sor="";
  62. for (int i = 0; i < sopa[posicion].length; i++) {
  63. sor=sor+sopa[posicion][i];
  64. }
  65.  
  66. return sor;
  67.  
  68. }
  69.  
  70. public String getDiagonal(int xoy, int yex, boolean dire) {
  71. String sor="";
  72. if(dire==true) {
  73. int i= xoy; int j=yex;
  74. while((i<sopa.length)&&(j<sopa[i].length)) {
  75. sor+=sopa[i][j];
  76. i++;
  77. j++;
  78.  
  79. }
  80.  
  81. }else {
  82. int i= xoy; int j=yex;
  83. while((i<sopa.length)&&(j<=0)){
  84. sor+=sopa[i][j];
  85. i++;
  86. j--;
  87. }
  88. }
  89.  
  90. return sor;
  91.  
  92. }
  93.  
  94. public void printSopa() {
  95. for (int i = 0; i < sopa.length; i++) {
  96. System.out.println(sopa[i].toString());
  97. }
  98. }
  99.  
  100.  
  101.  
  102. }
  103.  
  104.  
  105. import java.io.BufferedReader;
  106. import java.io.File;
  107. import java.io.FileInputStream;
  108. import java.io.FileNotFoundException;
  109. import java.io.IOException;
  110. import java.io.InputStreamReader;
  111. import java.util.concurrent.Callable;
  112.  
  113. public class WordSopaThread implements Callable<Integer> {
  114.  
  115. public String word;
  116. public File f;
  117.  
  118.  
  119. public WordSopaThread(String word, File f) {
  120. super();
  121. this.word=word;
  122. this.f=f;
  123. }
  124.  
  125.  
  126. @Override
  127. public Integer call(){
  128. // TODO Auto-generated method stub
  129. new FileInputStream(f)))) {
  130. String line=in.readLine();
  131. return line.indexOf(word);
  132. } catch (FileNotFoundException e) {
  133. // TODO Auto-generated catch block
  134. return -1;
  135. } catch (IOException e1) {
  136. // TODO Auto-generated catch block
  137. return -1;
  138. }
  139.  
  140. }
  141.  
  142.  
  143. }
  144.  
  145.  
  146. public class SopaMain {
  147.  
  148. static String[] words= {"cazuela","sarten","martes","lunes","pepe"};
  149.  
  150. public static void main(String[] args) {
  151. // TODO Auto-generated method stub
  152.  
  153. List<Future> list=new ArrayList<>();
  154. ExecutorService executor=Executors.newFixedThreadPool(4);
  155. for(int i=0;i<10;i++) {
  156. list.add(executor.submit(new WordSopaThread(words[i], new File("sopa.data"))));
  157. }
  158.  
  159. for(Future f:list) {
  160. try {
  161. System.out.println(f.get());
  162. } catch (InterruptedException e) {
  163. // TODO Auto-generated catch block
  164. e.printStackTrace();
  165. } catch (ExecutionException e) {
  166. // TODO Auto-generated catch block
  167. e.printStackTrace();
  168. }
  169. }
  170. }
  171.  
  172. }
  173.  
  174.  
  175. public class Position {
  176.  
  177. public int x;
  178. public int y;
  179.  
  180. public int getX() {
  181. return x;
  182. }
  183. public void setX(int x) {
  184. this.x = x;
  185. }
  186. public int getY() {
  187. return y;
  188. }
  189. public void setY(int y) {
  190. this.y = y;
  191. }
  192.  
  193.  
  194.  
  195. }
  196.  
  197.  
  198. public class SopaApp {
  199.  
  200. public static void main(String[] args) throws FileNotFoundException {
  201. // TODO Auto-generated method stub
  202.  
  203. SopaFileHunder zw=new SopaFileHunder(200,200);
  204. WordSopaThread wd=new WordSopaThread(null, null);
  205. zw.printSopa();
  206. System.out.println(zw.getChar(0, 2));
  207. System.out.println(zw.getRow(0));
  208. System.out.println(zw.getCol(1));
  209. System.out.println(zw.getDiagonal(1, 0, true));
  210.  
  211. }
  212.  
  213. }
  214.  

Los códigos deben ir en etiquetas GeSHi


« Última modificación: 28 Octubre 2017, 14:09 pm por engel lex » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Problema kon sopa de letras en consola
.NET (C#, VB.NET, ASP)
thedios 4 5,568 Último mensaje 24 Enero 2010, 20:09 pm
por MANULOMM
Sopa de letras
Programación C/C++
Ivanovic 1 3,170 Último mensaje 11 Mayo 2010, 01:32 am
por .:BlackCoder:.
porfa sopa de letras en netbeans
Java
vero2508 7 11,858 Último mensaje 7 Julio 2010, 22:59 pm
por Debci
Sopa de letras que recorra una matriz de direcciones « 1 2 »
Programación C/C++
amgarciac 10 11,913 Último mensaje 26 Agosto 2013, 18:56 pm
por amgarciac
Sopa de letras
Ejercicios
andrewzsz 1 3,367 Último mensaje 9 Julio 2015, 16:54 pm
por Eleкtro
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines