This site requires JavaScript, please enable it in your browser!
Greenfoot back
robobrax
robobrax wrote ...

2025/5/6

error with memomory card game

robobrax robobrax

2025/5/6

#
So I'm making a memory card game and string to add 6 cards and different positions, but not too sure what's going on, this is what I have. public void populateWorld() { Random random = new Random(); for(int i=0;i<6;i++) { arr Card;=new BkCard("backcard.jpg"); } BkCard cardy={ new BkCard("labron.jpg"),new BkCard("mickey.jpg"),new BkCard("s-1400.jpg"), new BkCard("labron.jpg"),new BkCard("mickey.jpg"),new BkCard("s-1400.jpg")}; intposition={{120,300},{320,300},{520,300},{120, 110},{ 320, 110},{520, 110}}; int t=0; for(t=0;t<cardy.length;t++){ addObject( Card, position, position); } }
danpost danpost

4 days ago

#
robobrax wrote...
So I'm making a memory card game and string to add 6 cards and different positions, but not too sure what's going on, this is what I have. << Code Omitted >>
Okay, no need for the Random line. Not sure what the first for loop is doing. Looks like you are trying to create and build an array. Example array builds are as follows:
Color[] colors = new Color[] {
    Color.RED,
    Color.GREEN,
    Color.BLUE
};

int[][] position = new int[][] {
    { 120, 300 }, { 320, 300 }, { 520, 300 }, {120, 110 }, { 320, 110 }, { 520, 110 }
};
Note what comes before the first opening squiggly bracket in each case. Arrays are Object instances and must be created using the new keyword. Assuming the arrays were built properly, the addObject line should be more like the following (here using array of Card objects named "cards":
addObject(cards[t], position[t][0], position[t][1]);
Note the '0' and '1' indecis for the array.
You need to login to post a reply.