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

2015/9/25

Good logic, bad syntax...

Pr0grammer Pr0grammer

2015/9/25

#
At the first, sorry for my bad english. I have the following scenario: Every 5 sec. spawns a red,blue or yellow balloon on a random position in the world. After the 5 Secs, the balloon stays between 10 and 30 second and disappears. I know that I have to work with Boolean and getRandomNumber, but don kno how. Here is my idea..
public class Spawner extends Actor
{
    
    int spawner;
    public boolean szenario0=false;
    public boolean szenario1=false;
    public boolean szenario2=false;

    public void act() 
    {
        int Greenfoot.getRandomNumber(3){
            if (0){
                szenario0;
            }
            if (1){
                szenario1;
            }
            if (2){
                szenario2;
            }
            if (!szenario1){ 
                spawner++;
                if (spawner >=300 ){

                    getWorld().addObject(new BalloonR(), Greenfoot.getRandomNumber(getWorld().getWidth()), 
                        Greenfoot.getRandomNumber(getWorld().getHeight()));
                    spawner=0;
                }
            }

        }  

    }
BalloonR = Red BalloonY = Yellow BalloonB = Blue Red class....
int remove;
    public void act()

    {   
        remove++;
        if (remove >= Greenfoot.getRandomNumber(300)+300){
            getWorld().removeObject(this);
            remove = 0;
        }

    }    

danpost danpost

2015/9/25

#
The code in the Spawner class act method looks like a good candidate for using the switch statement.
You need to login to post a reply.