I'm trying to create a scenario which creates cards that turn over when the proper key is hit, but I can't seem to understand what I'm doing wrong in actually adding new cards to the world.
the is the code for the LetterGame world class:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class LetterGame here.
*
* @author (your name)
* @version (a version number or a date)
*/
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, 425);
message = new Message();
//card = new Card();
for (int i = 0; i <3; i++)
{
addObject(new Card(selector, imageNamesFirstRow, imageNamesFirstRow.charAt(0), 39, 100));
}
}
public void act() {
selector.newCard();
}
public void showGuessMessage() {
message.showGuessImage();
}
public void showCorrectMessage() {
message.showCorrectAnswerImage();
}
}
and this is the code for the Card class:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Card here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Card extends Actor
{
private Selector selector;
private boolean faceUp;
private GreenfootImage backgroundImage;
private GreenfootImage faceImage;
private String letter;
//private String cardImage = {"ambulance", "butterfly", "elephant", "frog", "house", "kangaroo", "pig", "spider", "tent"};
public Card(Selector sel, String fileN, char let) {
selector = sel;
sel.addCard(this);
createInitialImage();
faceImage =new GreenfootImage(fileN);
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()
{
}
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);
}
}
when I compile the LetterGame class I get the following error message: "Constructor Card in class Card cannot be applied to the given types; required: Selector,java.lang,char found; Selector, java.lang.String,char,int,int reason: actual an..."
Any help would be greatly appreciated but thank you for your time nonetheless!

