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

2021/6/18

addObject() or setImage() won´t work

elektro elektro

2021/6/18

#
I wanted to do a quiz game, where you can see a picture and then you have to click on the right answer, but I can´t get the setImage() command working. Then I decided to simply create a class with the picture and add the Object tho the world with the addObject() command. This also doesnt work. ( But if i do it manually (by right clickingthe class and choose new ...(), then drag it in the world it works fine. Can anybody help me?
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Collections;
import java.util.regex.Pattern;
import java.util.regex.Matcher;


public class QuizWorld  extends World
{
    private List<Question> questions;
    private int questionNum;
    private int wrong;
    private int correct;
    private Actor imageActor = new Actor() {};
    

    
    public QuizWorld()
    {
        super(1000, 600, 1);
        
        questions = new ArrayList<Question>();

        String questionText = "Benenne?";
       
        ArrayList<Answer> answers = new ArrayList<Answer>();  
 
        answers.add(new Answer("Pentensäure", false));
        answers.add(new Answer("Butansäure", false));
        answers.add(new Answer("Pentansäure", true));
        answers.add(new Answer("Methan", false));
        Collections.shuffle(answers);
        Question question = new Question(questionText, answers);
        String explanation = "The correct answer was Pentansäure. ";
        question.setExplanation(explanation);
        questions.add(question);
Super_Hippo Super_Hippo

2021/6/18

#
Where did you try to use the methods?
danpost danpost

2021/6/21

#
You need an addObject line to put question in the world.
You need to login to post a reply.