So if I have:
How can I change the value to true if an object named card1 is clicked?
public static boolean card1Flipped = false;
public static boolean card1Flipped = false;
/** in Cards class */
// class field
public static final GreenfootImage back = new GreenfootImage("redback.png");
// instance field
private GreenfootImage face;
// in constructor
setImage(back);
face = new GreenfootImage(<? to be determined by card value and rank ?>);
// a method to flip the card
public void flip()
{
if (getImage() == back) setImage(face); else setImage(back);
}if (someCard.getImage() == Cards.back)
if (Card1.getImage() == Card1.front)
if (Card1.getImage() == Card1.front)
if (someCard.getImage() != Cards.back)
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Card1 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Card1 extends Cards
{ private GreenfootImage front = new GreenfootImage("images-1_burned.png");
private GreenfootImage back = new GreenfootImage("card1Back.jpg");
/**
* Act - do whatever the Card1 wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
changeImage();
ifCorrect();
}
public void changeImage()
{
if(Greenfoot.mouseClicked(this))
if (getImage() == front)
{
setImage(front);
}
else
{
setImage(back);
}
}
private void ifCorrect()
{
if((Card1.getImage() == front) && (Card1.getImage() == front))
{
Correct correct = new Correct();
getWorld().addObject(correct, 289, 190);
}
}
}
/** in Cards class */
protected Greenfootimage[] images = new GreenfootImage[2];
protected int imagesIndex;
public void act()
{
if (Greenfoot.mouseClicked(this))
{
imagesIndex = (imagesIndex+1)%2; // alternates in values between zero and one
setImage(images[imagesIndex]);
if (imagesIndex == 1) getWorld().addObject(new Correct(), getX(), getY()+100);
}
}
/** in Card1 class (and similar in others) */
public Card1()
{
images = { new GreenfootImage("card1Back.jpg"), new GreenfootImage("images-1_burned.png") };
}