import becker.robots.*;
import becker.io.*;

class MysteryRobot extends Robot
{
    // In addition to hte normal things we have to think about, 
    // we also want to remember the number of things to pick up.
    int howManyThingsPickedUp = 0;  
	 
	 	// the =0 is  technically not needed - 
		// howManyThingsPickedUp will get the value zero automatically

    MysteryRobot( City c, int st, int ave, Direction dir, int num)
    {
        super(c, st, ave, dir, num);
    }
    
    public void pickThingIfPresent()
    {
        if(this.canPickThing())
        {
            this.pickThing();
				
            this.howManyThingsPickedUp = this.howManyThingsPickedUp + 1;
        }
    }	
    
    public void collectRow()
    {
        while(this.frontIsClear() )
        {
            this.move();
            this.pickThingIfPresent();
        }
    }
	 public void printNumberOfThingsPickedUp()
	 {
	 	System.out.println("Picked up " + this.howManyThingsPickedUp + " things!");
	 }
}

public class InstVar_Demo_1 extends Object
{
    public static void main(String[] args)
    { 
        City ForgetsVille = new City(7, 10);
        // 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, 7, Direction.WEST, 0);
        
        new Thing(ForgetsVille, 4, 1);
        new Thing(ForgetsVille, 4, 2);
        new Thing(ForgetsVille, 4, 3);
        new Thing(ForgetsVille, 4, 5);
        new Thing(ForgetsVille, 5, 2);
        new Thing(ForgetsVille, 5, 3);
		  new Wall(ForgetsVille, 4, 0, Direction.EAST);

        mary.collectRow();
		  mary.printNumberOfThingsPickedUp();
		  
		  // Check our answer:
		  System.out.println("Should have picked up :" + mary.countThingsInBackpack() +" things.");
		  
    }
}

