Ver Mensaje Individual
  #1 (permalink)  
Antiguo 10/05/2010, 10:21
xxcom
 
Fecha de Ingreso: mayo-2010
Mensajes: 7
Antigüedad: 14 años
Puntos: 0
ayuda con problema en codigo

buenas a todos, el problema que tengo es de un juego bingo, aqui pongo el que yo he realizado, no me da errores, pero tiene que tener algun/os fallo/os en la implementacion del codigo, pero a pesar de darle vueltas no lo encuentro.

algunas partes de codigo van comentadas, ya que son partes que he ido realizando y para no borrarlas las he dejado comentada por no perder las ideas.

son dos clases (Bingo y CartonBingo) y el Main que debe ser ese, no se le puede cambiar nada.

aqui va el codigo:

Bingo.java

Código [java]:
Ver original
  1. package juegobingo;
  2. import java.io.*;
  3. public class Bingo
  4. {
  5.     final int MAXBOLAS=500;
  6.     final int ibol;
  7.     final int vbolas[];
  8.  
  9.      public Bingo()
  10.      {
  11.          this.ibol=0;
  12.          this.vbolas=new int[MAXBOLAS];
  13.      }
  14.      public int SacarBola()
  15.      {
  16.          int bola=(int)(Math.random()*MAXBOLAS);
  17.  
  18.          return bola;
  19.      }
  20.      private boolean YaUsado(int n)
  21.      {
  22.          boolean enc;
  23.  
  24.          enc=false;
  25.          for(int i=0;i<vbolas.length;i++)
  26.          {
  27.              if(vbolas[i]==n)
  28.              {
  29.                  enc=false;
  30.              }
  31.              else
  32.              {
  33.                  enc=true;
  34.              }
  35.          }
  36.         return enc;
  37.      }
  38.      public void MostrarBolas()
  39.      {
  40.          for(int i=0;i<vbolas.length;i++)
  41.          {
  42.              System.out.print("Bolas extraidas: "+vbolas[i]+", ");
  43.          }
  44.      }
  45.      public void GenerarFicheroBolas()
  46.      {
  47.          InputStreamReader isr=new InputStreamReader(System.in);
  48.          BufferedReader br=new BufferedReader(isr);
  49.          //String dato;
  50.  
  51.          File f1;
  52.          FileWriter fw;
  53.  
  54.          try
  55.          {
  56.              f1=new File("Fbolas.txt");
  57.              fw=new FileWriter(f1);
  58.  
  59.              if(f1.exists())
  60.              {
  61.                  f1.createNewFile();
  62.                  this.MostrarBolas();
  63.                  //System.out.println("El fichero GenerarFicheroBolas.txt se ha creado correctamente");
  64.              }
  65.              else
  66.              {
  67.                  System.out.println("No se ha podido crear el fichero GenerarFicheroBolas.txt");
  68.              }
  69.              fw.close();
  70.          }
  71.          catch(Exception ex)
  72.          {
  73.              System.out.println("Errores en la lectura del fichero GenerarFicheroBolas.txt: "+ex);
  74.          }
  75.      }
  76. }

CartonBingo.java

Código java:
Ver original
  1. package juegobingo;
  2.  
  3. import java.io.*;
  4. public class CartonBingo
  5. {
  6.     final int filas=3;
  7.     final int columnas=9;
  8.     final int rango=500;
  9.     private int boleto[][];
  10.     private boolean estadoboleto[][];
  11.     private boolean haylinea;
  12.     private boolean haybingo;
  13.     public int lineapremio;
  14.  
  15.      public CartonBingo()
  16.      {
  17.          this.boleto=new int[filas][columnas];
  18.          this.estadoboleto=new boolean[filas][columnas];
  19.          this.haylinea=false;
  20.          this.haybingo=false;
  21.          this.lineapremio=-1;
  22.      }
  23.      private boolean EsRepetido(int num)
  24.      {
  25.          boolean enc=false;
  26.  
  27.          for(int i=0;i<boleto[filas].length;i++)
  28.          {
  29.              for(int j=0;j<boleto[columnas].length;j++)
  30.              {
  31.                  if(num==boleto[filas][columnas])
  32.                  {
  33.                      enc=true;
  34.                  }
  35.                  else
  36.                  {
  37.                      enc=false;
  38.                  }
  39.              }
  40.          }
  41.          return enc;
  42.      }
  43.      public void RevisarNumero(int num)
  44.      {
  45.          boolean enc;
  46.  
  47.          enc=false;
  48.          for(int i=0;i<boleto[filas].length;i++)
  49.          {
  50.              for(int j=0;j<boleto[columnas].length;j++)
  51.              {
  52.                  if(num==boleto[i][j]/*==estadoboleto[i][j]*/)
  53.                  {
  54.                      estadoboleto[i][j]=true;
  55.                      enc=true;
  56.                      this.ComprobarLineas();
  57.                      this.ComprobarBingo();
  58.                  }
  59.              }
  60.          }
  61.      }
  62.      public boolean ComprobarLineas()
  63.      {
  64.          boolean enc;
  65.  
  66.          enc=false;
  67.          for(int i=0;i<estadoboleto.length;i++)
  68.          {
  69.              if(EsLinea(i))
  70.              {
  71.                  enc=true;
  72.              }
  73.              else
  74.              {
  75.                  enc=false;
  76.              }
  77.          }
  78.          return enc;
  79.      }
  80.      private boolean EsLinea(int fil)
  81.      {
  82.          boolean enc;
  83.  
  84.          enc=false;
  85.          for(int i=0;i<estadoboleto[fil].length;i++)
  86.          {
  87.              if(estadoboleto[fil][i]==enc)
  88.              {
  89.                  enc=false;
  90.              }
  91.              else
  92.              {
  93.                  enc=true;
  94.              }
  95.          }
  96.          return enc;
  97.      }
  98.      public boolean ComprobarBingo()
  99.      {
  100.          boolean enc;
  101.  
  102.          enc=false;
  103.          for(int i=0;i<estadoboleto[filas].length;i++)
  104.          {
  105.              for(int j=0;j<estadoboleto[columnas].length;j++)
  106.              {
  107.                  if(estadoboleto[i][j]==true)
  108.                  {
  109.                      enc=true;
  110.                  }
  111.                  else
  112.                  {
  113.                      enc=false;
  114.                  }
  115.              }
  116.          }
  117.          return enc;
  118.      }
  119.      public boolean HayLinea()
  120.      {
  121.          boolean enc;
  122.  
  123.          enc=false;
  124.          /*for(int i=0;estadoboleto[filas].length;i++)
  125.          {
  126.              if(estadoboleto[i]==true)
  127.              {
  128.                  enc=true;
  129.              }
  130.              else
  131.              {
  132.                  enc=false;
  133.              }
  134.              for(int j=0;j<estadoboleto[columnas].length;j++)
  135.              {
  136.                  enc=true;
  137.              }
  138.          }*/
  139.          return enc;
  140.      }
  141.      public boolean HayBingo()
  142.      {
  143.          boolean enc;
  144.  
  145.          enc=false;
  146.          for(int i=0;i<estadoboleto.length;i++)
  147.          {
  148.              for(int j=0;j<estadoboleto.length;j++)
  149.              {
  150.                  if(estadoboleto[i][j]==true)
  151.                  {
  152.                      enc=true;
  153.                  }
  154.                  else
  155.                  {
  156.                      enc=false;
  157.                  }
  158.              }
  159.          }
  160.          return enc;
  161.      }
  162.      public void MostrarCarton()
  163.      {
  164.          for(int i=0;i<boleto[filas].length;i++)
  165.          {
  166.              System.out.println(boleto[i]);
  167.              for(int j=0;j<boleto[columnas].length;j++)
  168.              {
  169.                  System.out.println(boleto[j]);
  170.              }
  171.          }
  172.      }
  173.      public void GenerarFicheroCarton(int ind)
  174.      {
  175.          InputStreamReader isr=new InputStreamReader(System.in);
  176.          BufferedReader br=new BufferedReader(isr);
  177.          //String dato;
  178.  
  179.          File f1;
  180.          FileWriter fw;
  181.  
  182.          try
  183.          {
  184.              f1=new File("Fich"+ind+".txt");
  185.              fw=new FileWriter(f1);
  186.  
  187.              if(!f1.exists())
  188.              {
  189.                  f1.createNewFile();
  190.                  this.MostrarCarton();
  191.              }
  192.              else
  193.              {
  194.                  System.out.println("El fichero Fichind.txt no se creo correctamente");
  195.              }
  196.              fw.close();
  197.          }
  198.          /*File fichero=new File("Fich"+ind+".txt");
  199.  
  200.          InputStreamReader isr;
  201.          BufferedReader br;
  202.  
  203.          try
  204.          {
  205.              isr=new InputStreamReader(System.in);
  206.              br=new BufferedReader(isr);
  207.  
  208.              fw=FileWriter(File);
  209.  
  210.              if(fichero.createNewFile())
  211.              {
  212.                  this.MostrarCarton();
  213.                  System.out.println("El fichero GenerarFicheroCarton.txt se ha creado correctamente");
  214.              }
  215.              else
  216.              {
  217.                  System.out.println("No se pudo crear el fichero GenerarFicheroCarton.txt");
  218.              }
  219.          }*/
  220.          catch(Exception ex)
  221.          {
  222.              System.out.println("Errores en la lectura del fichero GenerarFicheroCarton.txt: "+ex);
  223.          }
  224.      }
  225. }

el main va en un nuevo tema, ya que no lo puedo incluir en este mensaje.