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

2013/6/28

What is wrong with my code can someone please enlighten?

qsapp.3 qsapp.3

2013/6/28

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Lobster here.
 *
 * @author (Quinn Sapp)
 * @version (27 June 2013)
 */
public class Lobster extends Animal
{
    /**
    * Act - do whatever the Lobster wants to do. This method is called whenever
    * the 'Act' or 'Run' button gets pressed in the environment.
    */
    public void act(){
        start();
        move(3);
        turnAtEdge();
        randomTurn();
        tryToEatCrab();
        stop();
   }
   public static void start(){
        if (Greenfoot.start());
    }// Add your action code here.
    public void turnAtEdge(){
        if (atWorldEdge()){
        turn(17);
    }//end if    
   }
   public void randomTurn() {
       if (Greenfoot.getRandomNumber(100)<10)
    {
        turn(5);
    }//end if
   }
    public void tryToEatCrab(){
        if(canSee(Crab.class))
    {
        eat(Crab.class);
    }
    public static void stop(){
        if (Greenfoot.stop());
    }//end
   }
}
erdelf erdelf

2013/6/28

#
if you could say what it is supposed to do and what exactly doesnt work, that would be great. If your problem is that the program stops after one act cycle, remove the stop call in the act cycle
qsapp.3 qsapp.3

2013/6/28

#
The program wont static void stop it says there is an illegal start of expression. what its supposed to do is that there are worms crabs and lobsters. i am trying to get the lobsters to stop moving when they finish eating all of the crabs. But i cant figure out what im doing wrong. Thank you
erdelf erdelf

2013/6/28

#
first, replace the stop line of your act cycle with this
if(getWorld().getObjects(Lobster.class).length() == 0)
stop()
oh and dont make the stop method static
danpost danpost

2013/6/28

#
Line 41 is an 'end if' bracket and your next method is inside this method. To fix, remove line 45 and insert it at line 41 (or move the 'stop' method down outside the next closing bracket that is not part of the 'stop' method).
You need to login to post a reply.