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

2016/8/10

Problems with the methods of 'eating' objects

AlazaeInNeedOfHelp AlazaeInNeedOfHelp

2016/8/10

#
I'm having trouble with extremely simple code. The problem is that Greenfoot is not identifying the "canSee" and "eat" methods. Please help! This is the code (keep in mind 'canSee' and 'eat' are underlined in red. /** * Check whether we can see Dot01. If we can, eat it. */ public void tryToEatDot01() { if (canSee(Dot01.class) ) { eat(Dot01.class); Dot01Eaten++; if (Dot01Eaten == 17) { gameOver(); } } }
Super_Hippo Super_Hippo

2016/8/10

#
'canSee' and 'eat' are methods of the Animal class. You can only use them in the Animal class or in a subclass of Animal (or if you manually create the methods). Just rename the methods to 'isTouching' and 'removeTouching' which are the right methods from the Actor class.
You need to login to post a reply.