INTRODUCTION:
I'm making a small chess game where I use pictures to represent all the pieces, all my pieces are controlled by an function that draws them on the bord. the position of all the pieces is recorded in an array, but now I want to use what is recorded in the array to select what image is needed on what tile on the board, so far I have got a 99% working script with only one problem in it.
MAIN PROBLEM:
java does not except what is in my array to select the right picture I loaded earlier:
void tekenstukken(){
for(int x = 0 ; x < 8 ; x++){
for(int y = 0 ; y < 8 ; y++){
image(schaakstukken[y][x], x*blokgroote, y*blokgroote, blokgroote, blokgroote);
// -------- blokgroote is dutch for blocksize --------
} } }
in this code the only thing that does not work is schaakstukken[y][x]
this holds the names of the IPmage
variables i made earlier:
String[][] schaakstukken = new String[][]{ //schaakstukken means chesspieces in dutch
{"Tb","Hb","Rb","Qb","Kb","Rb","Hb","Tb"}, //Tb is my name for the Tower on the Black side, the other names are simulair
{"Pb","Pb","Pb","Pb","Pb","Pb","Pb","Pb"},
{ "" , "" , "" , "" , "" , "" , "" , "" },
{ "" , "" , "" , "" , "" , "" , "" , "" },
{ "" , "" , "" , "" , "" , "" , "" , "" },
{ "" , "" , "" , "" , "" , "" , "" , "" },
{"Pw","Pw","Pw","Pw","Pw","Pw","Pw","Pw"},
{"Tw","Hw","Rw","Qw","Kw","Rw","Hw","Tw"}
};
here is my ENTIRE CODE:
String[][] schaakstukken = new String[][]{
{"Tb","Hb","Rb","Qb","Kb","Rb","Hb","Tb"},
{"Pb","Pb","Pb","Pb","Pb","Pb","Pb","Pb"},
{ "" , "" , "" , "" , "" , "" , "" , "" },
{ "" , "" , "" , "" , "" , "" , "" , "" },
{ "" , "" , "" , "" , "" , "" , "" , "" },
{ "" , "" , "" , "" , "" , "" , "" , "" },
{"Pw","Pw","Pw","Pw","Pw","Pw","Pw","Pw"},
{"Tw","Hw","Rw","Qw","Kw","Rw","Hw","Tw"}
};
int breedte = 800;
int hoogte = breedte;
int blokgroote = breedte/8;
int blokkleur1 = #ffffff;
int blokkleur2 = #999999;
PImage Tb;
PImage Hb;
PImage Rb;
PImage Qb;
PImage Kb;
PImage Pb;
PImage Tw;
PImage Hw;
PImage Rw;
PImage Qw;
PImage Kw;
PImage Pw;
void setup(){
size(breedte, hoogte);
noStroke();
Tb = loadImage("Tb.png");
Hb = loadImage("Hb.png");
Rb = loadImage("Rb.png");
Qb = loadImage("Qb.png");
Kb = loadImage("Kb.png");
Pb = loadImage("Pb.png");
Tw = loadImage("Tw.png");
Hw = loadImage("Hw.png");
Rw = loadImage("Rw.png");
Qw = loadImage("Qw.png");
Kw = loadImage("Kw.png");
Pw = loadImage("Pw.png");
tekenbord();
tekenstukken();
}
void draw(){
}
void tekenbord(){
for(int x = 0 ; x < 8 ; x++){
for(int y = 0 ; y < 8 ; y++){
if((x+y)%2 == 0){
fill(blokkleur1);
}else{
fill(blokkleur2);
}
rect(x*blokgroote, y*blokgroote, blokgroote, blokgroote);
} } }
void tekenstukken(){
for(int x = 0 ; x < 8 ; x++){
for(int y = 0 ; y < 8 ; y++){
image(schaakstukken[y][x], x*blokgroote, y*blokgroote, blokgroote, blokgroote);
} } }
When I disable tekenstukken()
my code runs fine and draws an empty chessboard. if i replace schaakstukken[y][x]
by Tb
or one of the other names I get a chessboard filled with 1 kind of chess piece.
NOTE: My code is not finished yet I will later add an fuction that changes the array that controls the chess pieces according to what the player changes on the board.
Aucun commentaire:
Enregistrer un commentaire