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

2019/5/10

I need help with a beginner memory game, I can't get my card to match

samNY samNY

2019/5/10

#
This is what I have so far and I need help as to what to do further
public class Card extends Actor
{  
    GreenfootImage backImage = new GreenfootImage("card back black.png");
    GreenfootImage cardImage;
    int count;
    static int paired;
    static Card first, second;
    Card match;
    int score;
    
    public Card(GreenfootImage temp)
    {
        cardImage = temp;
        count = 0;
        setImage(backImage);       
    }
    public void act()
    {
        itsAMatch();
    }
     
    public int getCount()
    {
        return count;
    }
    
    public void incCount()
    {
        count = count + 1;
    }
        
    public void flip()
    {
        if (Greenfoot.mouseClicked(this))
        {
            setImage(cardImage);
        }
    }
    
    public void itsAMatch()
    {
        /*if (CardImage = CardImage)
        {
            getWorld().remove();
        }
        else
        {
            setImage(backImage);
        }*/
    }

    
    public String toString()
    {
        return cardImage.toString();
    }
    
}
Just fix the code LMAO
Super_Hippo Super_Hippo

2019/5/10

#
I would probably control it from the world and not from the cards. If the cards should do it on their own, you can have one static field which saves the card which was clicked on first. So when you click a second card, you can decide if this card's image equals the static one and after this check, set the static card variable back to null.
You need to login to post a reply.