crazymob
06-14-2007, 03:12 AM
Hey guys. I was wondering if you could help me with a java assignment I have due soon. The task was to create a static chess board using a multidimensional array and using characters as the peices (K = king, P = Pawn, etc etc).
From what I know, i've done everything right, but when ever I compile it I get an "incompatible types" on each line of the chess[0][1]=" "; etc etc.
import java.applet.Applet;
import java.awt.*;
public class Ex15CHESS extends Applet {
char[][] chess = new char[2][3];
public void init() {
chess[0][0]="R";
chess[0][1]="k";
chess[0][2]="B";
chess[1][0]="K";
chess[1][1]="Q";
chess[1][2]="P";
}
public void paint (Graphics g) {
g.drawString(" "+chess[0][0]+" "+ chess[0][1]+" "+chess[0][2]+" "+chess[1][0]+" "+ chess[1][1]+" "+chess[0][2]+" "+chess[0][1]+" "+ chess[0][0]+" ",20, 20);
g.drawString(" "+chess[1][0]+" "+ chess[1][1]+" "+chess[1][2]+" ",20, 40);
g.drawString(" "+chess[2][0]+" "+ chess[2][1]+" "+chess[2][2]+" ",20, 60);
}
}
Anyway, that's all of it. Any help at all would be appreciated.
Also, could someone point me in the direction of how I would actually use java to draw the chess board itself?
Thanks
From what I know, i've done everything right, but when ever I compile it I get an "incompatible types" on each line of the chess[0][1]=" "; etc etc.
import java.applet.Applet;
import java.awt.*;
public class Ex15CHESS extends Applet {
char[][] chess = new char[2][3];
public void init() {
chess[0][0]="R";
chess[0][1]="k";
chess[0][2]="B";
chess[1][0]="K";
chess[1][1]="Q";
chess[1][2]="P";
}
public void paint (Graphics g) {
g.drawString(" "+chess[0][0]+" "+ chess[0][1]+" "+chess[0][2]+" "+chess[1][0]+" "+ chess[1][1]+" "+chess[0][2]+" "+chess[0][1]+" "+ chess[0][0]+" ",20, 20);
g.drawString(" "+chess[1][0]+" "+ chess[1][1]+" "+chess[1][2]+" ",20, 40);
g.drawString(" "+chess[2][0]+" "+ chess[2][1]+" "+chess[2][2]+" ",20, 60);
}
}
Anyway, that's all of it. Any help at all would be appreciated.
Also, could someone point me in the direction of how I would actually use java to draw the chess board itself?
Thanks