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

2012/4/29

Letter game flipping cards

miko122 miko122

2012/4/29

#
Hello I am trying to create a scenario where in the end a bunch of cards are in the world and when it starts one will flip and a user has to guess the first letter and if its right a message will appear and flip another card. If guess wrong the user has to keep guessing. So far this is what i have i am supposed to have 9 cards up. I only have one in the world now im trying to figure out how to flip it first and guess. I am completely lost and if anyone could help it would be much appreciated. thanks LetterGame 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, 450); message = new Message(); //card = newCard(); for (int i=0;i<3;i++) { addObject( new Card(selector, imageNamesFirstRow, imageNamesFirstRow. charAt (0)), 40, 100); } //and before this comment } public void act() { selector.newCard(); } public void showGuessMessage() { message.showGuessImage(); } public void showCorrectMessage() { message.showCorrectAnswerImage(); } /** * Prepare the world for the start of the program. That is: create the initial * objects and add them to the world. */ } 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() { } 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); } }
You need to login to post a reply.