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

2018/2/23

How I can add something just for a perioade

Jennifer1234 Jennifer1234

2018/2/23

#
Hello everyone! I am trying to make a game . If I am touching an object with another one I want to show three object: an question and 2 possible answers . (I made images with this 3 objects)I succeed on this part , but I want to stop for a while the game (for the player could answer at the question) . And then , I want when i click the good answer to remove the all three object and when i click the bad answer the same things. You can help me,please?
Vercility Vercility

2018/2/23

#
Jennifer1234 wrote...
Hello everyone! I am trying to make a game . If I am touching an object with another one I want to show three object: an question and 2 possible answers . (I made images with this 3 objects)I succeed on this part , but I want to stop for a while the game (for the player could answer at the question) . And then , I want when i click the good answer to remove the all three object and when i click the bad answer the same things. You can help me,please?
Why do both answers do the same o.o? Use Greenfoot.ask(String string)
Jennifer1234 Jennifer1234

2018/2/26

#
Well, I haven't know how I can remove the question with that 2 answers after I choose one of this answers. Of course, when I click the good answer , I want to add some points on my counter, and then the game keep working on .For the bad answer I want to remove those things (3 objects ...) and the game keep working on. Also , I want the game to be stop , until I chose the answer. If you could help me more, I will appreciate for a lot.
danpost danpost

2018/2/26

#
If you use the same world to ask the question, then you would have to modify every act method in your project so that everything "pauses" to wait for a response. If you use a separate world, and after the response, return to the original world, you would not have to modify all the act methods. In the questioning world (which I will call QWorld), you would have something like this:
import greenfoot.*;

public class QWorld extends World
{
    MyWorld gameWorld;
    Actor[] answers;
    Actor correctAnswer;

    public QWorld(MyWorld world, String... qnas)
    {
        super(600, 400, 1);
        gameWorld = world;
        Actor question = createText(qnas[0]);
        answers = new Actor[qnas.length-1];
        for (int i=1; i<qnas.length; i++) answers[i-1] = createText(qnas[i]);
        correctAnswer = answers[0];
        java.util.Collections.shuffle(java.util.Arrays.asList(answers));
        addObject(question, 300, 100);
        for (int i=0; i<answers.length; i++) addObject(answers[i], 300, 200+50*i);
    }

    private Actor createText(String text)
    {
        Actor textActor;
        // textActor = whatever you now use to create the text objects
        return textActor;
    }

    public void act()
    {
        if (!Greenfoot.mouseClicked(null)) return;
        Actor clicked = Greenfoot.getMouseInfo().getActor();
        if (!answers.contains(clicked)) return;
        if (correctAnswer == clicked)
        {
            // have points added in gameWorld
            /**   example (not to be taken as shown):  gameWorld.counter.add(3); */
        }
        Greenfoot.setWorld(gameWorld);
    }
}
Jennifer1234 Jennifer1234

2018/2/26

#
I need more explanations from you because I'm not such a good person at this...I hope you have some free time. I don t know how I create an text , because of that I made images with the text(in paint). I try to explain what kind of game I try to make. Well , I have a taxi car and some people on map. When the car touch one person and then eat the person (eat because I want to disappear that person) , should appear three object which are 3 images with text:the question and two answer(and I have also an red answer and an green answer to change every answer in function of his duty). The car is moved by keys , but the car stops when colect 200 point or lose (when the cop's cars catch the car). If you have some advices or you can help me in another way , that will be amazing...Anyway,I thank you for a lot!
danpost danpost

2018/2/26

#
You can create a subclass of Actor and name it Aktor (or whatever; sometimes I use 'SimpleActor', but 'Aktor' is shorter). Here is ALL its code:
public class Aktor extends greenfoot.Actor {}
You can do all the basic things with an object created from this class -- give it an image and rotation, add it to a world and detect mouse clicks on it. For an image with text, create a GreenfootImage object using the 'GreenfootImage(String, int, Color, Color)' constructor. For example:
Color textColor = Color.BLACK;
Color backColor = new Color(0, 0, 0, 0); // transparent
String text = "Hello!";
int textSize = 30;
GreenfootImage image = new GreenfootImage(text, textSize, textColor, backColor);
I broke it down so you could see each part. You can then set the image to an actor (or more to the point -- an Aktor object).
danpost danpost

2018/2/26

#
The 5-liner in my last post (without line 3) can be placed at line 25 above preceded by:
actor = new Aktor(); // could be combined with line 24
and followed by:
actor.setImage(image); // before the 'return actor;' line
Jennifer1234 Jennifer1234

2018/2/27

#
public void act()
    {
        if (!Greenfoot.mouseClicked(null)) return;
        Actor clicked = Greenfoot.getMouseInfo().getActor();
 !       if (!answers.contains(clicked)) return;
        if (correctAnswer == clicked)
        {
            // have points added in gameWorld
            /**   example (not to be taken as shown):  gameWorld.counter.add(3); */
        }
        Greenfoot.setWorld(gameWorld);
    }
I thank you for a lot for the explanations in your last post, but where I put "!" ,it s an error . The word "contains". What can I put in that place ?
danpost danpost

2018/2/27

#
Trry:
if (clicked == null || !answers.contains(clicked)) return;
You need to login to post a reply.