New problem.I have that code to keep only 2 cards clicked at once. When I click a wrong pair, I would assume the counter be set to zero, but if I click another wrong pair, the cards do not reset. I think it is a problem with the numbers in the counter, but I can't figure it out. changeImage(); is in every card.
static public int counter = 0;
public void changeImage()
{
if(Greenfoot.mouseClicked(this))
{
if(card1Flipped)
{
counter = counter - 1;
setImage(front);
card1Flipped = false;
}
else
{
if(counter < 2)
{
counter = counter + 1;
setImage(wolf);
card1Flipped = true;
ifWrong();
}
}
}
if((card1Flipped == true) && (card2Flipped == true))
{
Greenfoot.delay(30);
displayCorrect();
getWorld().removeObjects(getWorld().getObjects(Card2.class));
getWorld().removeObjects(getWorld().getObjects(Card1.class));
}
}
public void ifWrong()
{
if(counter == 2)
{
if((card1Flipped == true) && (card3Flipped == true))
{
Greenfoot.delay(30);
card1Flipped = false;
card3Flipped = false;
Card1 card1 = (Card1) getWorld().getObjects(Card1.class).get(0);
card1.setImage(front);
Card3 card3 = (Card3) getWorld().getObjects(Card3.class).get(0);
card3.setImage(front);
counter = 0;
}
else if ((card1Flipped == true) && (card4Flipped == true))
{
Greenfoot.delay(30);
card2Flipped = false;
card4Flipped = false;
Card1 card1 = (Card1) getWorld().getObjects(Card1.class).get(0);
card1.setImage(front);
Card4 card4 = (Card4) getWorld().getObjects(Card4.class).get(0);
card4.setImage(front);
counter = 0;
}
}
}

