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

2017/3/16

help on list and iterator

jasmine.h jasmine.h

2017/3/16

#
private void carridgeAlliesRight()//executes the preceding function on the other enemies
    {
        List allies = getWorld().getObjects(Enemy1.class);//list of all the other enemies
        Iterator i = allies.iterator();//create an iterator in that list
        while(i.hasNext()) {//if theres more enemies to move
            Enemy1 a = (Enemy1) i.next();//put the enemy into a variable
            if ( a != this) {//if they arent us (cuz we all ready moved)
                a.carridgeRight();//move them down
                a.setLocation(a.getX(), a.getY());
                a.shouldMove = 0;
                a.movetimer = 0;
                if (getImage() != a.getImage()) {
                    setImage(a.getImage());
                }
            }
        }
    }
it says it cannot find the symbols list and iterator and i'm assuming i have to make a list or iterator? please help i'm new to greenfoot and we had to download this scenario.
danpost danpost

2017/3/16

#
You need to import the List and Iterator classes.
jasmine.h jasmine.h

2017/3/16

#
how do I do that? thanks
Super_Hippo Super_Hippo

2017/3/16

#
Should be this:
import java.util.List;
import java.util.Iterator;
danpost danpost

2017/3/16

#
At the top of the code, where you see the following line:
import greenfoot.*;
add the following lines:
import java.util.List;
import java.util.Iterator;
You need to login to post a reply.