Pick one of the following problems to do for your interclass problem. Note that these problems require different scenarios. (Dot Scenario) (Maze Scenario)

1. Monochrome Filter - In the Dot scenario, call the populateRandom() method. Write a method that when called on a Dot, all Dots with that color will be removed from the board. You should not worry about having this happen while running the scenario.


    public void removeSameColor() {
        World w=getWorld();
        List<Dot> dots=w.getObjects(Dot.class);
        for(int i=0; i<dots.size(); i++) {
            Dot d=dots.get(i);
            if(d.color.equals(color)) {
                w.removeObject(d);
            }
        }
    }
		

2. Ripple Effect - In the Dot scenario, call the populateBlue() method. Using this grid of blue Dots, write a method that makes all Dots around the one this method is called on change colors (if blue, make it red and vice versa). This method should take an integer argument for the radius of this effect. You should not worry about having this happen while running the scenario.


    public void ripple(int radius) {
        World w=getWorld();
        List<Dot> dots=w.getObjects(Dot.class);
        for(int i=0; i<dots.size(); i++) {
            Dot d=dots.get(i);
            int dx=getX()-d.getX();
            int dy=getY()-d.getY();
            if(dx*dx+dy*dy<=radius*radius) {
                if(d.color.equals("blue")) {
                    d.color="red";
                    d.setImage("button-red.png");
                } else {
                    d.color="blue";
                    d.setImage("button-blue.png");
                }
            }
        }
    }
		

3. Random Rat Race - In the Maze scenario, create a Mouse that starts at coordinates (1,0) and walks around randomly until it finds the Cheese, at which point it stops. The trick is that it isn't allowed to move diagonally or step on walls. Also include a method, int getSteps(), that reports how many steps were taken.


    public void act() 
    {
        if(getWorld().getObjectsAt(getX(),getY(),Cheese.class).size()>0) {
            return;
        }
        int dir=Greenfoot.getRandomNumber(4);
        if(dir==0) {
            move(0,-1);
        }
        if(dir==1) {
            move(1,0);
        }
        if(dir==2) {
            move(0,1);
        }
        if(dir==3) {
            move(-1,0);
        }
    }
    
    public void move(int dx,int dy) {
        int x=getX()+dx;
        int y=getY()+dy;
        if(getWorld().getObjectsAt(x,y,Wall.class).size()==0 && x>=0 &&
                x<getWorld().getWidth() && y>=0 && y<getWorld().getHeight()) {
            setLocation(x,y);
            numSteps++;
        }
    }
    
    public int getNumSteps() {
        return numSteps;
    }
    
    private int numSteps=0;
		

4. Controlled Rat Race - This is the same as option 3, but instead of having the mouse roam randomly, have its motion controlled by the user with the arrow keys.


    public void act() 
    {
        if(getWorld().getObjectsAt(getX(),getY(),Cheese.class).size()>0) {
            return;
        }
        if(Greenfoot.isKeyDown("up")) {
            move(0,-1);
        }
        if(Greenfoot.isKeyDown("right")) {
            move(1,0);
        }
        if(Greenfoot.isKeyDown("down")) {
            move(0,1);
        }
        if(Greenfoot.isKeyDown("left")) {
            move(-1,0);
        }
    }
    
    public void move(int dx,int dy) {
        int x=getX()+dx;
        int y=getY()+dy;
        if(getWorld().getObjectsAt(x,y,Wall.class).size()==0 && x>=0 &&
                x<getWorld().getWidth() && y>=0 && y<getWorld().getHeight()) {
            setLocation(x,y);
            numSteps++;
        }
    }
    
    public int getNumSteps() {
        return numSteps;
    }
    
    private int numSteps=0;