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

2015/7/8

I´m a beginner with Greenfoot please help me.

Kieser Kieser

2015/7/8

#
What did I wrong? public class robbe extends Actor { /** * Act - do whatever the robbe wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { frissFische(); } public void frissFische() { if(isTouching(fisch.class)) { eat(fisch.class) ; } } }
Super_Hippo Super_Hippo

2015/7/8

#
1. Use the code tags to post code. 2. Follow the java convention: class names should start with an uppercase letter. 3. In case of "What did I (do) wrong?", describe what is the problem. In this case, you could post the error message. 4. Finally (and to help with your problem), the method 'eat' doesn't exist in the 'Actor' class. It exists in the 'Animal' class, but your class doesn't extend it, so it doesn't inherit its methods. Furthermore, the 'eat' method in the 'Animal' class needs an actor as the parameter and not a class. You can either create a method named 'eat' or you simply use a method which already exists in the 'Actor' class: 'removeTouching'.
danpost danpost

2015/7/8

#
To be sure, the 'eat' method in the 'Animal' class needs a class, not an actor, as the parameter. Of note, the difference between the pairing of 'canSee' and 'eat' with the pairing of 'isTouching' and 'removeTouching' is that the touching methods acquire other objects whose images intersect any part of the image of the actor while the Animal class methods only acquire other objects whose images intersect the center-point of the image of the actor.
You need to login to post a reply.