swing - Java : Memory Game -
i working on memory game project, click on 2 cards check if pictures same or not. problem facing if both cards don't have same picture, second picture not appear , first 1 closes well.
here code think has sort of error in.
public void actionperformed(actionevent e) { clicks +=1; card clicked = (card)e.getsource(); clicked.changecolor(); for(int i=0;i<16;i++) if(clicked == cards.get(i)) opencardindices.add(i); if(clicks==2 && opencardindices.get(opencardindices.size()-1)!=opencardindices.get(opencardindices.size()-2)) { if(cards.get(opencardindices.get(opencardindices.size()-1)).equals(cards.get(opencardindices.get(opencardindices.size()-2)))) { (cards.get(opencardindices.get(opencardindices.size()-1))).removeactionlistener(this); (cards.get(opencardindices.get(opencardindices.size()-2))).removeactionlistener(this); } else { opencardindices.remove(opencardindices.size()-1); opencardindices.remove(opencardindices.size()-1); //lockcards(); unlockcards(); } clicks = 0; }
your code tells that.
you want else
clause like:
- delay 2 seconds before hiding cards unlock.
or maybe
- leave cards alone until click on 1 of them again. require counter going 1 2 , 3, turn them over.
not gonna write code clue.
Comments
Post a Comment