Hi but could i have the code for placing objects into the world. There should be at least five of them spawning. My World class is The_House and my actors are Villian and The_Jail. It would be better if I could have seven of The_Jail.


1 2 | int x = Greenfoot.getRandomNumber(getWidth()); int y = Greenfoot.getRandomNumber(getHeight()); |
1 2 3 4 5 6 | public void addActor(Actor actor) { int x = Greenfoot.getRandomNumber(getWidth()); int y = Greenfoot.getRandomNumber(getHeight()); addObject(actor, x, y); } |
1 | addActor( new Villian()); |
1 | for ( int i= 0 ; i< 7 ; i++) addActor( new The_Jail()); |
1 2 3 4 5 6 7 | public void addActor(Actor actor) { int x = Greenfoot.getRandomNumber(getWidth()); int y = Greenfoot,getRandomNumber(getHeight()); addObject(Villian,x,y) } |
1 | for ( int i= 0 ; i< 1 +Greenfoot.getRandomNumber( 7 ); i++) addActor( new The_Jail()); |
1 | for ( int i= 1 +Greenfoot.getRandomNumber( 7 ); i> 0 ; i--) addActor( new The_Jail()); |
1 2 | int count = 1 +Greenfoot.getRandomNumber( 7 ); for ( int i= 0 ; i<count; i++) addActor( new The_Jail()); |
1 2 | int x = Greenfoot.getRandomNumber(getWidth()); int y = Greenfoot.getRandomNumber(getHeight()); |
1 2 3 4 5 6 | public void addActor(Actor actor) { int x = Greenfoot.getRandomNumber(getWidth()); int y = Greenfoot.getRandomNumber(getHeight()); addObject(actor, x, y); } |
1 | addActor( new Villian()); |
1 | for ( int i= 0 ; i< 7 ; i++) addActor( new The_Jail()); |