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

2016/12/4

Help with Loops and arrays inside of World

Snans Snans

2016/12/4

#
My teacher wants me to do this Inside of the OceanWorld constructor use a loop and an array and write code to create 4 fish when the world is compiled. Could you provide an example with how I would do this? I don't just want the answer because I'd like to really understand more about arrays and loops
Tritos Tritos

2016/12/4

#
for(int n = 1; n<= 4; n++)
        {
            addObject(new Fish(), 0, 0);
        }
This would be a very simple example for doing that. You could alse make the position the fish starts at change like so(for example)
for(int n = 1; n<= 4; n++)
        {
            addObject(new Fish(), n, n);
        }
You need to login to post a reply.