This is my array:
pieces[2][1]=new Pawn("Bpn1");
pieces[2][2]=new Pawn("Bpn2");
pieces[2][3]=new Pawn("Bpn3");
pieces[2][4]=new Pawn("Bpn4");
pieces[2][5]=new Pawn("Bpn5");
pieces[2][6]=new Pawn("Bpn6");
pieces[2][7]=new Pawn("Bpn7");
pieces[2][8]=new Pawn("Bpn8");
pieces [1][1]=new Rook("BR1");
pieces [1][2]=new Knight("BN1");
pieces [1][3]=new Bishop("BB1");
pieces [1][4]=new King("BKing");
pieces [1][5]=new Queen("BQueen");;
pieces [1][6]=new Bishop("BB2");
pieces [1][7]=new Knight("BN2");
pieces [1][8]=new Rook("BR2");
pieces[7][1]=new Pawn("Wpn1");
pieces[7][2]=new Pawn("Wpn2");
pieces[7][3]=new Pawn("Bpn3");
pieces[7][4]=new Pawn("Wpn4");
pieces[7][5]=new Pawn("Wpn5");
pieces[7][6]=new Pawn("Wpn6");
pieces[7][7]=new Pawn("Wpn7");
pieces[7][8]=new Pawn("Wpn8");
pieces [8][1]=new Rook("WR1");
pieces [8][2]=new Knight("WN1");
pieces [8][3]=new Bishop("WB1");
pieces [8][4]=new King("WKing");
pieces [8][5]=new Queen("WQueen");;
pieces [8][6]=new Bishop("WB2");
pieces [8][7]=new Knight("WN2");
pieces [8][8]=new Rook("WR2");
i am trying to print it in two loops. but it doesnt work!!!
String[] drawNull=new String[5];
for(int i=0;i<pieces.length;i++){
for(int j=0;j<pieces[i].length;j++){
if(pieces[2][j]==null){
drawNull[0]="__________________";
drawNull[1]="| |";
drawNull[2]="| |";
drawNull[3]="| |";
drawNull[4]="|_______________ |";
for(int m=0;m<drawNull.length;m++)
System.out.println(drawNull[m]);
}
else{
pieces[2][j].print();
}
}
}
print() method is basically located in each chess piece class. here is an example of a pawn class:
String[] drawWhitePiece=new String[5];
public void print() {
if(name.charAt(0)=='B'){ // that is the first letter of the name of the piece. if it is black or white.
drawBlackPiece[0]=" _____";
drawBlackPiece[1]=" |_ _|";
drawBlackPiece[2]=" _| |_ ";
drawBlackPiece[3]=" _| Bpawn |_";
drawBlackPiece[4]="|__________|";
for(int i=0;i<drawBlackPiece.length;i++){
System.out.println(drawBlackPiece[i]);
}
System.out.println( " "+ name);
}