/** 
 * @author CPSC 111 class and Tamara Munzner
 * @date Wed Mar 31
 *
 * Finish up and test Bunny class that we started on Monday. Many design alternatives discussed. 
 */
public class Bunny {

	// must declare fields so we have storage for our class
	// want our fields to be private for encapsulation
	// don't want these fields to constants, so don't use 'final'

	// could have separate declaration lines for each field, but more concise to combine them
	//	private int x;
	//	private int y;
	//	private int carrots;

	private int x,y,carrots;
	
	// constructor should be public not private
	// don't want a void return type for a constructor, because you'd toss away all your work
	public Bunny() {
		// can we say x vs this.x here? yes, ok just say x here, no other variable named x in our scope.
		x = 10;
		y = 10;
		carrots = 5;
		// alternative: store these values as constants in fields, and set them there. also legal, but not necessary
		// what if set default values for fields instead of in constructor. style is usually to do *everything* in constructor, rather than some stuff when declare fields, but more complex stuff must be in constructor (like for loops)	
	}
	
	public void hop(int direction) {
		// no, don't need for loops here! just need to change location according to parameter
		//for (int i = 0; i < 10; i++) {
			//for (int j = 0; j < 10; j++) {

		if (carrots <= 0) {
			System.out.println("This bunny can't hop");
			return;
		}
		// would also be legal to test as we go
		// or to have an if/else statement
		if (direction == 12) {
			y++;
			carrots--;
			System.out.println("hop");
		} else if (direction == 9) {
			x--;
			carrots--;
			System.out.println("hop");
		} else if (direction == 6) {
			y--;
			carrots--;
			System.out.println("hop");
		} else if (direction == 3) {
			x++;
			carrots--;
			System.out.println("hop");
		}
		// carrots--; // if we decrement carrots here, we'd use up energy even for garbage input. so let's move this to inside the conditional
		
	}
	public void displayInfo() {
		// return direction; // no, we're supposed to print, not return, the values!
		System.out.println("This bunny is at position "+x+", "+y);
		System.out.println("This bunny has "+carrots+" carrots");
	}
	public static void main(String[] args)
	  {
	    System.out.println("Testing Peter");
	    Bunny peter = new Bunny();
	    peter.displayInfo();
	    peter.hop(12);
	    peter.hop(12);
	    peter.hop(9);
	    peter.displayInfo();
	    System.out.println("Testing Emily");
	    Bunny emily = new Bunny();
	    emily.displayInfo();
	    emily.hop(9);
	    emily.hop(9);
	    emily.hop(9);
	    emily.hop(12);
	    emily.hop(9);
	    emily.hop(12);
	    emily.displayInfo();
	  }
	
}

