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

2014/1/4

problems with memory game

kingsint kingsint

2014/1/4

#
hi, I have just stared programming with greenfoot, and I thought an easy game to make would be a memory game, but i have problem with it: the cards are already in random positions and if I click one it will turn over. But I don't know what I have to do when I want to turn the 2 cards back when they are not the same, and also when i do find a good couple that the cards will stay turned over.
JetLennit JetLennit

2014/1/4

#
I think that it would be eaisier to help if you posted the current code
danpost danpost

2014/1/4

#
Sounds like you need a couple of instance fields in your subclass of World to hold the chosen cards ('cardOne' and 'cardTwo' as Card object references). If the first is null, then any clicked face-down card would be set to cardOne and flip the card up. If first is not null and second is null, any clicked face-down card would be set to cardTwo and flip the card up. If neither is null then compare values. If values are different, flip both cards down and nullify fields. Also, charge any penalty for non-matching pair. If values match, nullify fields and give any kudos for correct matching.
kingsint kingsint

2014/1/4

#
danpost, thank you I think I will be able to make it now
Vigelandzoon Vigelandzoon

2014/1/17

#
public void opencard() { int duiker = 0; int duiker2 = 0; if (duiker == duiker2) { if(Greenfoot.mouseClicked(Duiker.class)) { setImage("duiker_tcm46-175501.jpg"); duiker = 1; if(Greenfoot.mouseClicked(duiker2)) { duiker2 = 1; } { getWorld().removeObject(this); } } else if(Greenfoot.mouseClicked(this)) { setImage("duiker_tcm46-175501.jpg"); Greenfoot.delay(150); setImage("150px_RGB_WEBSAFE_D_B_G_26-29652.gif"); } } } i have the same problem my code wont work
You need to login to post a reply.