I am currently working on a memory game project, where you click on two cards to check if the pictures are the same or not. The problem that I am facing is that if both cards don't have the same picture, the second picture does not appear and the first one closes as well.
Here is the code which I think has some sort of an 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;
}