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

2017/4/18

loop with pause. /between every loop a like to have a pause for 3 seconds

t-niftarlake t-niftarlake

2017/4/18

#
Source: import greenfoot.*; /** * Write a description of class SeaBackground here. * * @author (your name) * @version (a version number or a date) */ public class SeaBackground extends World { /** * Constructor for objects of class SeaBackground. * */ public SeaBackground() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(600, 400, 1); addObject (new Boat(), 50, 80); addObject (new pirateboatv6(), 50, 150); addObject (new pirateboatv6(), 300, 200); addObject (new pirateboatv6(), 100, 350); int i = 1; while (i<100) { //between every loop a like to have a pause for 3 seconds addObject (new Bombv2(), 50, 150); addObject (new Bombv2(), 50, 150); addObject (new Bombv2(), 50, 150); addObject (new Bombv2(), 50, 150); addObject (new Bombv2(), 50, 150); i = i + 1; } } }
danpost danpost

2017/4/18

#
I presume by pause that you mean a delay for spawning bombs during gameplay. I am not sure that you want 100 spawning times or whether you wish for spawning to continue until the game ends. End your world constructor after the adding of the pirate boats. You need to spawn the bombs within an act method. The following would be for until the game ends:
// instance field
int i;

// act method
public void act()
{
    if (i == 0) {
        addObject (new Bombv2(), 50, 150);
        addObject (new Bombv2(), 50, 150);
        addObject (new Bombv2(), 50, 150);
        addObject (new Bombv2(), 50, 150);
        addObject (new Bombv2(), 50, 150);
    }
    i++;
    if (i == 180) i = 0;
}
The last two lines can also be written as follows:
if (++i == 180) i = 0;
// also equivalent to that is this
i = ++i % 180;
t-niftarlake t-niftarlake

2017/4/18

#
Hi Danpost, thanks for your quick reaction. I have tried many solution but (also from you) but i always get the error: for this code: public void act() Illegal start of exprssion AND ':' expected **************************************************************************** import greenfoot.*; /** * Write a description of class SeaBackground here. * * @author (your name) * @version (a version number or a date) */ public class SeaBackground extends World { /** * Constructor for objects of class SeaBackground. * */ public SeaBackground() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(600, 400, 1); addObject (new Boat(), 50, 80); addObject (new pirateboatv6(), 50, 150); addObject (new pirateboatv6(), 300, 200); addObject (new pirateboatv6(), 100, 350); int i = 1; while (i<100) { // instance field int i; // act method public void act() { if (i == 0) { addObject (new Bombv2(), 50, 150); addObject (new Bombv2(), 50, 150); addObject (new Bombv2(), 50, 150); addObject (new Bombv2(), 50, 150); addObject (new Bombv2(), 50, 150); } i++; if (i == 180) i = 0; } i = i + 1; } } }
t-niftarlake t-niftarlake

2017/4/18

#
Hi Danpost, I upload the scenario, maybe you can take a look: Greenfoot v23 Thanks for helping me Ties
danpost danpost

2017/4/18

#
Replace these lines:
        int i = 1;
      
        while (i<100)
        {
with this:
}
and remove these lines:
         i = i + 1;
       }

    }
Timon Timon

2017/4/18

#
I have a problem. What must I write that an actor can not go throught an ather acter??Please Help me.
t-niftarlake t-niftarlake

2017/4/18

#
Hi Danpost, You are realy great. It works fine now. Thanks a lot. Ties
danpost danpost

2017/4/18

#
Timon wrote...
I have a problem. What must I write that an actor can not go throught an ather acter??Please Help me.
@Timon, please start a new discussion thread on your issue -- and show your attempted codes.
Timon Timon

2017/4/19

#
Ou sorry.
You need to login to post a reply.