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

2017/3/16

I need help urgently please!

Scarlett Scarlett

2017/3/16

#
Good evening In my game i have the avatar eating the burgers, but i want a apple which is the wombat treat to spawn once 10 burgers has been eaten. I did some of the code here, but it seems that it is not right because the apple does not spawn at all. Could someone please help me out with figuring out my problem. Thank you in advance Scarlett
  public void Wombat_Treat() 
    {
        int x;
        int y;
        if(Burger==0) {
                    
             Wombat_Treat WB1= new Wombat_Treat();
             addObject(WB1, Greenfoot.getRandomNumber(700), Greenfoot.getRandomNumber(700)); 
                    
             x = (Greenfoot.getRandomNumber(700));
             y = (Greenfoot.getRandomNumber(700));
             addObject(WB1, x, y);
                    
                    
                    
                }
Super_Hippo Super_Hippo

2017/3/16

#
The question is if this code is executed at all.
danpost danpost

2017/3/16

#
If 'Burger' counts the number of burgers eaten and you want an apple to spawn after every ten burgers are eaten, then line 5 should be:
if (Burger%10 == 0) {
However, the code is probably misplaced. It needs to be located immediately after the following:
Burger++;
// or
Burger += 1;
// or
Burger = Burger+1;
Or, at least, the conditional should be placed there (it can still call this method, but without conditions in the method itself).
You need to login to post a reply.