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

2014/9/24

I cant compile my work can you someone help me out please

coder04 coder04

2014/9/24

#
I get a error saying cannot find symbol- variable my world
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Enemylaser here.
 * 
 */
public class Enemylaser extends Mover

{
    private int life; 
    /**
     * Act - do whatever the Enemylaser wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
     public void act()
     {
        move(20.0);
        eat();
        life--;
       if (life == 0)
       {  
           getWorld().removeObject(this);  
       }
       ifAtWorldEdge();
     }
       
    public void ifAtWorldEdge()  
    {  
        if (atWorldEdge())  
        {  
             getWorld().removeObject(this);  
        }  
    }  
 
     public void eat()
    {
        Actor Ship;
        Ship = getOneObjectAtOffset(0, 0, Ship.class);
        if (Ship != null)
        {
            World world;
            world = getWorld();
            GameOver gameover = new GameOver();
            myWorld.addObject(gameover, myWorld.getWidth()/2, myWorld.getHeight()/2);
            world.removeObject(Ship);
        }  
    } 
    
}
erdelf erdelf

2014/9/24

#
in line 44. replace every occurence of myWorld with world
coder04 coder04

2014/9/24

#
Now it says non-static method get Width World.addObject(gameover, World.getWidth()/2, World.getHeight()/2);
coder04 coder04

2014/9/24

#
This is my code now still have some errors so it wont compile
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Enemylaser here.
 * 
 */
public class Enemylaser extends Mover

{
    private int life; 
    /**
     * Act - do whatever the Enemylaser wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
     public void act()
     {
        move(20);
        eat();
        life--;
       if (life == 0)
       {  
           getWorld().removeObject(this);  
       }
       ifAtWorldEdge();
     }
       
    public void ifAtWorldEdge()  
    {  
        if (atWorldEdge())  
        {  
             getWorld().removeObject(this);  
        }  
    }  
     
     public void eat()
    {
        Actor Ship;
        Ship = getOneObjectAtOffset(0, 0, Ship.class);
        if (Ship != null)
        {
            World world;
            world = getWorld();
            GameOver gameover = new GameOver();
            World.addObject(gameover, World.getWidth()/2, World.getHeight()/2);
            Space space = (Space)World;
            Counter counter = space.getCounter();
            counter.addScore();
            world.removeObject(Ship);
        }  
    }
}   
    
    
    
    
    
    
erdelf erdelf

2014/9/24

#
i said you have to replace it with "world" not "World"
You need to login to post a reply.