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

2018/4/3

When actor reached score 10, he can go to the next level

Findr Findr

2018/4/3

#
Hi, I need code, when actor reach score 10, he can go to the next level. Here is my code in actor Counter, where I have score counter.
 public int score;
    /**
     * Act - do whatever the Counter wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {

    }   

    public Counter()
    {
        updateImage();
    }

    private void updateImage()
    {
        setImage(new GreenfootImage("SEBRANÝCH KYTEK: 10/" +score, 24, Color.BLACK, Color.WHITE));
    }

    public void addScore()
    {
        score++;
        updateImage();
    }
And here is code in player actor.
public void stretSKytkou()
    {
        if(isTouching(Kytka.class))
        {
            World myWorld = getWorld();

            Louka louka = (Louka)myWorld;
            Counter counter = louka.getCounter();
            counter.addScore();
            this.getWorld().removeObject(this.getOneIntersectingObject(Kytka.class));

        }
    }
nolttr21 nolttr21

2018/4/3

#
assuming that the next level is in another world, put this in your act method of your counter
if (score > 9)
{
    Greenfoot.setWorld(new WhatEverYourNextWorldIsCalled());
}
danpost danpost

2018/4/3

#
nolttr21 wrote...
assuming that the next level is in another world, put this in your act method of your counter
if (score > 9)
{
    Greenfoot.setWorld(new WhatEverYourNextWorldIsCalled());
}
The act method of the Counter class is not really an appropriate place for that check. If in the Counter class at all, it should be at the end of the addScore method. I feel, however, that it should be modified to go either in the stretSKytkou method in the class of the player or in a method in your Louka class that is called from the stretSKytkou method.
You need to login to post a reply.