Java Gridworld How could I call a marked class? (marker interface)

69 views Asked by At

How could I call a marked Class? I need to implement the class Spider so that if it finds a Babybug and it will be eaten.

// marked Interface

public interface Eatable {

}   

// Class BabyBug

public class BabyBug extends Bug implements Eatable{

public Babybug(){
    this.setColor(Color.ORANGE);
    Age=0;
}
@Override   
public void act()
    {
        super.act();

        Location Loc =getLocation();
        Grid<Actor> grid =getGrid();
        if (this.getAge()>=4){
            removeSelfFromGrid();       
            AdultBug Adult = new AdultBug();
            Adult.putSelfInGrid(grid, Loc);
            }
            return;
        }

    }

}

// Class Spider is the subclass of Insect and Insect is a subclass of Critter

public class Spider extends Insect 
    public void act(){
       super.act();
    }

    public void processActors(ArrayList<Actor> actors)
    {

        for (Actor a : actors)
        {
            if (a instanceof Eatable)
            a.removeSelfFromGrid();

        }
    }

}

But the problem is that the Spider is not eaten the Babybugs and if I put:

Babybug a =new Babybug();
// instead
for (Actor a : actors)

I get some errors like: This actor is not contained in a grid. How could I fix it? thanks!

0

There are 0 answers