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

2011/12/21

lobster problem

programmer22 programmer22

2011/12/21

#
says ')' expected import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Lobster here. * * @author (your name) * @version (a version number or a date) */ public class Lobster extends Actor { /** * 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() { moveAround(); eat(); } public void moveAround() { move(4); if (Greenfoot.getRandomNumber(100) < 10) { turn (Greenfoot.getRandomNumber(90) - 45); } if (getX() <= 5 1 1 getX() >= getWorld().getWidth() - 5) { turn(180); } if (getY() <= 5 1 1 getY() >= getWorld().getWidth() - 5) { turn(180); } } public void eat() { Actor crab; crab = getOneObjectAtOffset(0, 0, Crab.class); if (crab != null) { World world; world = getWorld(); world.removeObject(crab); Greenfoot.playSound("eating.wav"); } } } and yes i know it looks weird with the brackets at the end like that but it says its ok so the problem is right after the 5 in if (getX() <= 5 1 1 getX() >= getWorld().getWidth() - 5)
kiarocks kiarocks

2011/12/21

#
In that line you either need the and "&&" or the or "||" (those are pipe things, not L's!) in between 511 and getX(). I think you want the or.
kiarocks kiarocks

2011/12/21

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

/**
 * Write a description of class Lobster here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Lobster extends Actor
{
    /**
     * 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() 
    {
        moveAround();
        eat();
    }
    public void moveAround()
    {
        move(4);
        if (Greenfoot.getRandomNumber(100) < 10)
        {
            turn (Greenfoot.getRandomNumber(90) - 45);
        }
        if (getX() <= 5 1 1 || getX() >= getWorld().getWidth() - 5)
        {
            turn(180);
        }
        if (getY() <= 5 1 1  || getY() >= getWorld().getWidth() - 5)
        {
            turn(180);
        }
            
    }
    public void eat()
     {
        Actor crab;
        crab = getOneObjectAtOffset(0, 0, Crab.class);
        if (crab != null)
        {
            World world;
            world = getWorld();
            world.removeObject(crab);
            Greenfoot.playSound("eating.wav");
    

        }      }   }
You need to login to post a reply.