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

2016/3/7

What is wrong with my code?

LordGaben LordGaben

2016/3/7

#
I'm trying to make a counter and watch this video https://www.youtube.com/watch?v=WIifij-961o and try to do the same please help I need to finish this game before next week here is my code
import greenfoot.*;

/**
 * Write a description of class PinkCloud here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class PinkCloud extends Actor
{
    private int points =0;
    private Counter counter;
    public PinkCloud(Counter pointCounter)
    {
        counter = pointCounter;
    }
    
    public void act() 
    {
        move();
        EatPinkMob();
    }    
    
    void move()
    {
        if (Greenfoot.isKeyDown("w"))
        {
            setLocation(getX(),getY()-4);
        }
        if (Greenfoot.isKeyDown("s"))
        {
            setLocation(getX(),getY()+4);
        }
        if (Greenfoot.isKeyDown("a"))
        {
            setLocation(getX()-4,getY());
        }
        if (Greenfoot.isKeyDown("d"))
        {
            setLocation(getX()+4,getY());
        }

        
    }
    
    void EatPinkMob()
    {
        if (isTouching(PinkMob.class))
        {
           removeTouching(PinkMob.class); 
        }
    }
    
    public void try2Eat()
    {
      if (canSee(PinkMob.class))
      {
          eat(PinkMob.class);
          counter.add(1);
          Greenfoot.playSound("slurp.wav");
      }
     
    }
}
danpost danpost

2016/3/7

#
The only line, that when executed, that will change the value of the counter is line 59; however, it is located in a method , 'try2Eat', that is not being called to execute.
You need to login to post a reply.