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

2016/1/8

half-world

Haloman13445 Haloman13445

2016/1/8

#
 private void checkMouseClick()
    {
        if (Greenfoot.mouseClicked(null)) 
        {
            World world = getWorld();
            List<Leaf> leaves = world.getObjects(Leaf.class);
            for (Leaf leaf : leaves)
            {
                leaf.changeImage();
            }
        }
    }
Haloman13445 wrote...
How would I modify this code so that only half the Leaves in the World change image when I click.
danpost danpost

2016/1/8

#
Haloman13445 wrote...
How would I modify this code so that only half the Leaves in the World change image when I click.
Put line 9 inside an if block whose condition is a 50:50 random chance. The result will not be exactly half -- but that may be more to your liking anyway.
You need to login to post a reply.