Hello I am trying to make a guessing card game and it should go like this where when it hits run one card should flip over and the user has to guess by letter but so far I can't seem to figure out how to get just one card to flip at a time and only display one of the three pictures. Here is the source code for card class and world class. I haven't yet wrote the code to try and guess the picture so any help would be greatly appreciated.
world class:
public class LetterGame extends World
{
private Selector selector;
private Message message;
private String imageNamesFirstRow = {"ambulance.png", "butterfly.png", "elephant.png"};
private String imageNamesSecondRow = {"frog.png", "house-03.png", "kangaroo.png"};
private String imageNamesThirdRow = {"pig.png", "tent.png", "spider.png"};
/**
* Constructor for objects of class LetterGame.
*
*/
public LetterGame()
{
// Create a new world with 500x500 cells with a cell size of 1x1 pixels.
super(500, 500, 1);
//This line creates the selector object - DO NOT remove or change this line.
selector = new Selector(this);
//Place your code for the constructor after this comment.
addObject( new Message(), 250, 480);
message = new Message();
//card = newCard();
for (int i=0;i<3;i++)
{
addObject( new Card(selector, imageNamesFirstRow, imageNamesFirstRow. charAt (0)), 100, 100);
addObject( new Card(selector, imageNamesFirstRow, imageNamesFirstRow. charAt (0)), 250, 100);
addObject( new Card(selector, imageNamesFirstRow, imageNamesFirstRow. charAt (0)), 400, 100);
addObject( new Card(selector, imageNamesSecondRow, imageNamesSecondRow. charAt (0)), 100, 250);
addObject( new Card(selector, imageNamesSecondRow, imageNamesSecondRow. charAt (0)), 250, 250);
addObject( new Card(selector, imageNamesSecondRow, imageNamesSecondRow. charAt (0)), 400, 250);
addObject( new Card(selector, imageNamesThirdRow, imageNamesThirdRow. charAt (0)), 100, 400);
addObject( new Card(selector, imageNamesThirdRow, imageNamesThirdRow. charAt (0)), 250, 400);
addObject( new Card(selector, imageNamesThirdRow, imageNamesThirdRow. charAt (0)), 400, 400);
}
//and before this comment
}
public void act() {
selector.newCard();
}
public void showGuessMessage() {
message.showGuessImage();
}
public void showCorrectMessage() {
message.showCorrectAnswerImage();
}
card class
public class Card extends Actor
{
private Selector selector;
private GreenfootImage backgroundImage;
private boolean faceUp;
private GreenfootImage faceImage;
private String letter;
private String cardImage= {"ambulance","butterfly","elephant","frog","house", "kangaroo","pig","spider","tent"};
public Card(Selector sel, String cardImages, char let) {
selector = sel;
sel.addCard(this);
createInitialImage();
faceImage= new GreenfootImage(cardImages);
faceUp=false;
letter= ""+ let;
//Add your code for the constructor after this comment
}
/**
* Act - do whatever the Card wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
turnOver();
}
public void turnOver() {
//setImage(faceImage);
if (faceUp){
setImage(backgroundImage);
faceUp=false;
}
else{
setImage(faceImage);
faceUp= true;}
}
private void createInitialImage() {
backgroundImage = new GreenfootImage(100, 100);
backgroundImage.setColor(java.awt.Color.BLUE);
backgroundImage.fillRect(0, 0, 100, 100);
setImage(backgroundImage);
}
}

