Hola, buenos dias!
Pues bien, yo tengo este código:
package Ajedrez;
public class Tablero {
Pieza array[][]=new Pieza[7][7];
public Tablero(){
for(int i=0;i<8;i++)
for(int j=0;j<8;j++)
array[ i][j]=new Pieza();
}
void iniciarPartida(){
for(int i=0;i<8;i+=7){
array [ i][0].pz=Piezas.TORRE;
array [ i][1].pz=Piezas.CABALLO;
array [ i][2].pz=Piezas.ALFIL;
array [ i][3].pz=Piezas.DAMA;
array [ i][4].pz=Piezas.REY;
array [ i][5].pz=Piezas.ALFIL;
array [ i][6].pz=Piezas.CABALLO;
array [ i][7].pz=Piezas.TORRE;
}
for(int i=0;i<8;i++){
array [7][ i].cl=Colores.NEGRO;
array [6][ i].pz=Piezas.PEON;
array [6][ i].cl=Colores.NEGRO;
array [1][ i].pz=Piezas.PEON;
array [1][ i].cl=Colores.BLANCO;
array [0 ][ i ].cl=Colores.BLANCO;
}
}
}
public static void main
(String args
[]){ Tablero mitabla= new Tablero();
//System.out.print(mitabla.toString());
}
}
class Pieza {
Piezas pz;
Colores cl;
public Pieza() {
this.pz=null;
this.cl=null;
}
}
enum Piezas{REY,DAMA,ALFIL,CABALLO,TORRE,PEON};
enum Colores{BLANCO,NEGRO};
Y cuando lo ejecuto me da el sgte. error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7
at Ajedrez.Tablero.<init>(Tablero.java:8)
at Ajedrez.Tablero.main(Tablero.java:78)
Yo creo que es del arranque, que no sabe muy bien donde empezar a ejecutarse. Lo digo por que me da fallo en la main y he estado indagando por ahi y es lo que me aparecía.
Agradecería cualquier ayuda.
Un saludo a todos!