Java 把名单变成演员(绿脚)

Java 把名单变成演员(绿脚),java,list,collision,Java,List,Collision,我正在为我的学校编程项目开发一款射击游戏,并使用演员碰撞检测 后来我意识到我需要使用另一种方法来返回一个区域中的所有参与者,但唯一的问题是它返回一个列表。我不知道如何使用列表,需要将列表中的每个元素都转换为参与者 以下是代码的一部分: MyWorld w = (MyWorld) getWorld(); List<Actor> a = getObjectsInRange(20, null) ; //if it hits the soldier if ( a i

我正在为我的学校编程项目开发一款射击游戏,并使用演员碰撞检测

后来我意识到我需要使用另一种方法来返回一个区域中的所有参与者,但唯一的问题是它返回一个列表。我不知道如何使用列表,需要将列表中的每个元素都转换为参与者

以下是代码的一部分:

MyWorld w = (MyWorld) getWorld();
    List<Actor> a = getObjectsInRange(20, null) ;
    //if it hits the soldier
    if ( a  instanceof Soldier)
    {
        Soldier s = (Soldier) a;
        //kill the enemy
        s.die();
        //add 100 score to the enemy
        w.addScore(100);
        //if the weapon is not laser
        if (weaponId != 2) 
        {
            //getting the world to make the bullet able to fire again
            w.setBulletLive(false); 
            //remove the bullet
            getWorld().removeObject(this); 

        }
    }
    // if it hits the enemy
    else if (a instanceof EnemyWeapon)
    {
        EnemyWeapon g = (EnemyWeapon) a; 
        //intercept the missile
        g.intercepted();
MyWorld w=(MyWorld)getWorld();
列表a=getObjectsInRange(20,空);
//如果击中士兵
如果(士兵的实例)
{
士兵s=(士兵)a;
//杀敌
s、 模具();
//给敌人加100分
w、 总分(100分);
//如果武器不是激光
if(武器ID!=2)
{
//让世界让子弹再次开火
w、 挫折(假);
//取出子弹
getWorld().removeObject(此);
}
}
//如果它击中敌人
else if(敌人武器的实例)
{
Enemy武器g=(Enemy武器)a;
//拦截导弹
g、 拦截();

如果要遍历参与者列表,可以执行以下操作:

for (Actor actor : listActors) {
    // here you should put your logic.
    ...
}

什么是Actor,它与其他对象的关系如何?您可能想从for(Actor-Actor:actors){core here}开始