import becker.robots.*;
import becker.io.*;

class MysteryRobot extends RobotSE
{
    int howManyThingsPerRow;
    
    // In addition to hte normal things we have to worry about, 
    // we also want to remember the number of things to pick up.
    MysteryRobot( City c, int ave, int st, int dir, int num, int numThingsPerRow)
    {
        super(c, ave, st, dir, num);
        this.howManyThingsPerRow = numThingsPerRow;
        System.out.println("There are " + this.howManyThingsPerRow + " things in each row!");
    }
    
    public void pickThingIfPresent()
    {
        if(this.isBesideThing())
        {
            this.pickThing();
        }
    }	
    
    public void collectRow()
    {
        int howManyCollectedFromThisRow = 0;
        while(howManyCollectedFromThisRow < this.howManyThingsPerRow)
        {
            this.pickThingIfPresent();
            this.move();
            howManyCollectedFromThisRow = howManyCollectedFromThisRow + 1;
        }
    }
}

public class ICE_09_Demo_1 extends Object
{
    public static void main(String[] args)
    { 
        City ForgetsVille = new City();
        // We want the robot to remember that a row of things is 3 intersections long
        // thus the new, additional argument (3) at the end of the normal ones.
        MysteryRobot mary = new MysteryRobot(ForgetsVille, 4, 4, Directions.WEST, 0, 3);
        
        new Thing(ForgetsVille, 1, 4);
        new Thing(ForgetsVille, 2, 4);
        new Thing(ForgetsVille, 3, 4);
        new Thing(ForgetsVille, 1, 5);
        new Thing(ForgetsVille, 2, 5);
        new Thing(ForgetsVille, 3, 5);

        CityFrame frame = new CityFrame(ForgetsVille);
        
        mary.move();
        mary.collectRow();
        mary.turnLeft();
        mary.move();
        mary.turnLeft();
        mary.move();
        mary.collectRow();
    }
}

