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

2015/9/30

Help me with my program please

steezyjapaneezy steezyjapaneezy

2015/9/30

#
I am working on the little-crab-5 scenario. 1. How do you make the crab give a certain sound after it turns more than 18 degrees?? It already moves when the left/right keys are pressed. What code am I supposed to add?
 public void checkKeypress()
    { 
        if (Greenfoot.isKeyDown("left")) 
        {
            turn(-4);
        }

        if (Greenfoot.isKeyDown("right")) 
        {
            turn(4);
        }
}
2. How can I make the lobsters eat every crab randomly? (Not always, but ever so often) I've already written the code for lobsters to eat them and make the crabs disappear.
public void lookForCrab()
    {
        if ( canSee(Crab.class) ) 
        {
            eat(Crab.class);
            Greenfoot.playSound("au.wav");
            Greenfoot.stop();
        }
Thanks for the help guys!
steezyjapaneezy steezyjapaneezy

2015/10/1

#
Any help?
GamemodeGod GamemodeGod

2015/10/2

#
My version is 2.4.2 and I can't type that command nor hit Ctrl + space to find that command. So can someone help me to play sound out? It says it cannot find "fanfare.wav", "slurp.wav" and "au.wav". Here is what I type: if (isTouching(elephant.class)) { removeTouching(elephant.class); Greenfoot.playSound("slurp.wav"); Greenfoot.stop(); } } then it says java couldn't open file "slurp.wav". if you change the if (isTouching(elephant.class)) to cansee , it will say cannot find method canSee. Needing help!
Mack Mack

2015/10/2

#
Steezyjapaneezy I posted the same question on here about lobsters eating every other crab randomly and I got some help! Try this code, it should work perfectly! // instance field private int touchCounter; // the 'lookForCrab' method public void lookForCrab() { // check for change in touching state if (isTouching(Crab.class) == (touchCounter % 2 == 0)) { // track state touchCounter = (touchCounter+1) % 4; // check for second touch if (touchCounter == 3) { removeTouching(Crab.class); Greenfoot.playSound("au.wav"); } } }
You need to login to post a reply.