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

2014/7/9

Need Help With a Class Project.

meganw21 meganw21

2014/7/9

#
I was given what was required for the project but was given absolutely no idea how to do it. Crab - you should create randomWalk and smellFlower methods...the Crab will walk "randomly" like the textbook discusses and will slow down whenever it comes in contact with a Flower (Hint...that is when the Crab can see the Flower) LadyBug - you should create a Fade method...the LadyBug will "fade" or lose some of its transparency each time a Crab crosses over it (Hint...that is, when the LadyBug can see a Crab) Frog - you should create a Jump method...the Frog will jump a certain distance (of your own choosing ) when a Crab crosses near it (Hint...that is, when the Frog can see a Crab... change the Frog's Y value...ie the distance from the top of the world) Flower - you should create a Blink method...the Flower will blink on and off continuously (Hint...save the Flower's current transparency in a variable, set the transparency to zero, and then set the transparency back to the value you have saved in the variable...you must also call Greenfoot's delay() method after setting/re-setting the transparency). In a week or two we will give you more help with the Flower's blinking, but we would like you to try this challenge first by yourself.
danpost danpost

2014/7/9

#
You will need to show what you have in those classes so far. Work on one thing at a time. Start with the Crab class (since you have it listed first above).
meganw21 meganw21

2014/7/9

#
So far for the crab class this is what I have public class Crab extends Animal { public boolean atWorldEdge() { if(getX() < 5 || getX() > getWorld().getWidth() - 5) return true; if(getY() < 5 || getY() > getWorld().getHeight() - 5) return true; else return false; } /** * Act - do whatever the Crab wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if (atWorldEdge()) { turn(Greenfoot.getRandomNumber(45)); } if (Greenfoot.getRandomNumber(100)<10) { turn(Greenfoot.getRandomNumber(45)-45); } move(Greenfoot.getRandomNumber(10)); } }
danpost danpost

2014/7/9

#
Where are the 'randomWalk' and 'smellFlower' methods? (at least try something) BTW -- what you have in your 'act' method appears to be what you might use for the 'randomWalk' method. The act method should pretty much state what the assignment asks for: if it can see a Flower object, smell the Flower object; else, walk randomly.
You need to login to post a reply.