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

2013/1/1

non-static method cannot be referenced from a static context

1
2
ctgreenfoot ctgreenfoot

2013/1/10

#
the counter in the crab class is a countdown clock which is a different thing and is working well. here is my crab class:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Crab here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Crab extends Animals
{
    /**
     * Act - do whatever the Crab wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    
    private Counter counter;
    
    public Crab(Counter pointCounter)
    {
        counter = pointCounter;
    }
    
    public void act() 
    {
       moveAndTurn(); 
       eatWorm();
      
    }  
   
    
    private void moveAndTurn()
    {  
       if (Greenfoot.isKeyDown ("space"))
            move (4);
       if (Greenfoot.isKeyDown ("right"))
            turn (3);
            
       if (Greenfoot.isKeyDown ("left"))
            turn (-3);
        }   
    private void eatWorm()
    {
    Actor Worm;
    Worm = getOneObjectAtOffset (0,0,Worm.class);
    if(Worm != null)
    {
         int x = Greenfoot.getRandomNumber(getWorld().getWidth());  
        int y = Greenfoot.getRandomNumber(getWorld().getHeight());  
        Worm.setLocation(x, y); 
        counter.add(1);
        Greenfoot.playSound ("eating.wav");
    }
    
    Actor RedWorm;
    RedWorm = getOneObjectAtOffset (0,0,RedWorm.class);
    if (RedWorm != null)
    {
    World world;
    world = getWorld ();
    world.removeObject (RedWorm);
    counter.add(5);
    Greenfoot.playSound ("eating.wav");
}
        
        if (counter.getValue () == 50)
        {
            Greenfoot.stop();
            Greenfoot.playSound ("fanfare.wav");
            getWorld().addObject(new GameWon(), getWorld().getWidth()/2, getWorld().getHeight()/2);
        }
        
    } 
}


i appreciate all your help!
ctgreenfoot ctgreenfoot

2013/1/10

#
sorry i meant that the counter is a point counter for how many worms the crab has eaten, not a countdown clock!
davmac davmac

2013/1/10

#
Your indentation is all messed up - it makes your code really hard to understand. Try pressing ctrl+shift+I in the editor.
ctgreenfoot ctgreenfoot

2013/1/10

#
fixed! thank you
ctgreenfoot ctgreenfoot

2013/1/11

#
would anyone be able to help me on this?
You need to login to post a reply.
1
2