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

2012/12/14

Little Crab 5 scenario- red worms

Peach Peach

2012/12/14

#
Is it possible to make red worms start to appear when a crab has eaten 10 green worms? If so how? What is the method and the codes?
Gevater_Tod4711 Gevater_Tod4711

2012/12/14

#
You need to count the worms your crab has already eaten. Then you check this value in the constructor of your worm class and it you have eaten more than 10 worms you change the image of your worm using setImage();
Peach Peach

2012/12/15

#
so is the method going to be something like: if wormsEaten = 10 setImage()
Gevater_Tod4711 Gevater_Tod4711

2012/12/15

#
well it would be a bit more than that but this is the basic idea.
Peach Peach

2012/12/28

#
do I need to create a new actor? and what would the exact method be? Thanks!
Peach Peach

2012/12/28

#
I've tried this (this is the worm subclass) but it keeps on saying "cannot find variable wormsEaten". what should i do? import greenfoot.World; import greenfoot.Actor; /** * Worm. A sand worm. Very yummy. Especially crabs really like it. * Author: Michael Kolling */ public class Worm extends Animal { public void populateRed() { if (wormsEaten = 10); setImage(redWorm.png); } }
Ploppy Ploppy

2012/12/28

#
if( wormsEaten = 10); { getWorld().addObject( new(), , ); }
Gevater_Tod4711 Gevater_Tod4711

2012/12/29

#
If the compiler cant find the variable wormsEaten you haven't declared it or you have declared it but somwhere (probably in an othere class) where you cant find it from your worm class. Have you got a variable wormsEaten somewhere? If yes show us the code then we can help you.
You need to login to post a reply.