All pastes #1016321 Raw Edit

Unnamed

public text v1 · immutable
#1016321 ·published 2008-05-12 22:12 UTC
rendered paste body
public class BlusterCritter extends Critter {
    
    private int courage;
    
    public BlusterCritter(int c) {
        super();
        courage = c;
        setColor(Color.YELLOW);
    }
    
    public ArrayList<Actor> getActors() {
        ArrayList<Actor> actors = new ArrayList<Actor>();
        Location loc = getLocation();
        for (int  r = loc.getRow() - 2; r <= loc.getRow() + 2; r++) {
            for (int c = loc.getCol() - 2; c <= loc.getCol() + 2; c++) {
                Location tempLoc = new Location(r,c);
                Grid<Actor> gr = getGrid();
                if ((gr.isValid(tempLoc)) && (gr.get(tempLoc) instanceof Critter)) {
                    actors.add(gr.get(tempLoc));                                                           
                }
            }
        }
        return actors;
    }
    
    public void processActors(ArrayList<Actor> actors) {
        Color myColor = getColor();
        if (actors.size() > courage) {
            setColor(myColor.darker());
        }
        else {
            setColor(myColor.brighter());
        }
        System.out.println(getColor());
    }
}