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

2014/9/1

method AddMushrooms in class Background cannot be applied to given types: etc... help please

roshiyoshi roshiyoshi

2014/9/1

#
public class Background extends World { public void act() { { { { if(Greenfoot.getRandomNumber(100)<10){ addObject(new Mushroom(),0,20); if (getObjects(Mushroom.class).size() == 0) addMushrooms(3); /** * Constructor for objects of class Background. * */ } } } } } /** * Constructor for objects of class Background. * */ public Background() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(600, 400, 1); prepare(); } /** * Prepare the world for the start of the program. That is: create the initial * objects and add them to the world. */ private void prepare() { Fish fish = new Fish(); addObject(fish, 296, 357); theCounter=new Counter(); addObject(theCounter, 73, 378); Mushroom mushroom = new Mushroom(); addObject(mushroom, 433, 242); Mushroom mushroom2 = new Mushroom(); addObject(mushroom2, 103, 287); Mushroom mushroom3 = new Mushroom(); addObject(mushroom3, 250, 84); Zombie zombie = new Zombie(); addObject(zombie, 492, 77); Zombie zombie2 = new Zombie(); addObject(zombie2, 138, 175); Zombie zombie3 = new Zombie(); addObject(zombie3, 169, 50); } private Counter theCounter; public Counter getCounter() { return theCounter; } private void addMushrooms() { Mushroom mushroom = new Mushroom(); addObject(mushroom, 433, 242); Mushroom mushroom2 = new Mushroom(); addObject(mushroom2, 103, 287); Mushroom mushroom3 = new Mushroom(); addObject(mushroom3, 250, 84); } }
NikZ NikZ

2014/9/1

#
You are calling addMushrooms() with a parameter int -- 3. addMushrooms doesn't have any parameters.
roshiyoshi roshiyoshi

2014/9/1

#
So what do I need to do?
Super_Hippo Super_Hippo

2014/9/1

#
Just delete the 3:
addMushrooms();
roshiyoshi roshiyoshi

2014/9/1

#
Thanks guys, much appreciated
danpost danpost

2014/9/1

#
The condition on this line:
if (getObjects(Mushroom.class).size() == 0)
will never be true because you have this line before it:
addObject(new Mushroom(),0,20);
roshiyoshi roshiyoshi

2014/9/1

#
So I should get rid of if (getObjects(Mushroom.class).size() == 0)  ?
danpost danpost

2014/9/1

#
I cannot say what you should do. What do YOU want to happen 10% of the time ( or about 6 times a second -- on average -- as regulated by 'if (Greenfoot.getRandomNumber(100)<10)' in a scenario running at normal speed )? Be specific and detailed.
roshiyoshi roshiyoshi

2014/9/6

#
All I want to happen is for the mushrooms to respawn once I shoot them
danpost danpost

2014/9/6

#
Then you really confused things with extra code in the act method of the Background class. Change it to this:
public void act()
{
    if (getObjects(Mushroom.class).isEmpty()) addMushrooms();
}
roshiyoshi roshiyoshi

2014/9/6

#
thanks so much danpost, really appreciate the help
You need to login to post a reply.