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

2017/1/25

Can't access Pacman from another class

TheGreenFoot TheGreenFoot

2017/1/25

#
Hello guys, I am currrently programming a game for school where the player can move pacman and has to dodge the lobsters. A am trying to access the "stopThatSound" method from the Lobster so the sound stops when Pacman is killed, but it says "not a statement" (at the dot between pacman and stopThatSound) when I try to access the method from the Lobster class. Can someone help me pls? (Sorry for my bad English, I am from Germany.) This is my Lobster class.
public class Lobster extends Animal
{

    public void act()
    {
        turnAtEdge();
        randomTurn();
        move();
        lookForCrab();
    }

    public void turnAtEdge()
    {
        if ( atWorldEdge() ) 
        {
            turn(17);
        }
    }

    public void randomTurn()
    {
        if (Greenfoot.getRandomNumber(100) > 90) {
            turn(Greenfoot.getRandomNumber(90)-45);
        }
    }

    /**
     * Versucht eine Krabbe zu fangen; d.h. prüft, ob wir auf eine Krabbe gestoßen sind.
     * Wenn ja, wird die Krabbe aus dem Spiel entfernt und die Ausführung des Programms beendet.
     */
    public void lookForCrab()
    {
        if ( canSee(Pacman.class) ) 
        {
           eat(Pacman.class);
           Pacmansworld pacmansworld = getWorld();
           Pacman pacman = pacmansworld.getPacman();
           pacman.stopThatSound;
        }
    }
}
This is the World class' code:
public class PacmansWorld extends World
{
    private Pacman thePacman;
    
    /**
     * Constructor for objects of class PacmansWorld.
     * 
     */
    public PacmansWorld()
    {    
        super(1000, 1000, 1);
        thePacman = new Pacman();
        addObject(thePacman, 5, 5);
    }
    
    public Pacman getPacman()
    {
        return thePacman;
    }
    
    
}
What did I do wrong?
danpost danpost

2017/1/25

#
Please refer to this discussion post.
You need to login to post a reply.