For my assignment I have to create the game 'memory'. I keep getting stuck on the part where I randomly give every card a color.
I first created this array
int rectColorArray[] ={BROWN, BROWN,WHITE, WHITE,RED, RED, GREEN, GREEN};
And made a loop in wich I hoped it would only pick each color once.
void drawCards(int rectColor){
int length = 50;
int xPos =0;
int yPos =0;
for(int i = 7; i >= 0; i--){
rectColor = rectColorArray[(int)random(0,rectColorArray.length)];
fill(rectColor);
rect(xPos,yPos, length, length);
xPos = xPos + length + 10;
splice(rectColorArray,i,1);
}
}
it seems as if 'splice' doesn't do anything, because I keep getting rects that doesn't give the wanted output.
So my final question is: Does anyone know how to fix this problem, or if I should use another technique.
Aucun commentaire:
Enregistrer un commentaire