package hws.hw10.controller;

import hws.hw10.simulator.Direction;
import hws.hw10.simulator.DroneController;

/**
 * INCORRECT control logic for the PhoneDrone.
 *
 * @author A team of "hoakey" programmers at an un-named university in VA.
 * @version 1.0
 */
public class FoneDroneController extends DroneController {

    private int[] location;

    /**
     * Explicit Value Constructor.
     *
     * @param number The phone number to look for
     */
    public FoneDroneController(String number) {
        super(number);
        this.location = null;
    }

    /**
     * Get the location of the phone (or null if it hasn't been found).
     *
     * @return The location of the phone (or null)
     */
    public int[] getLocationOfPhone() {
        return location;
    }

    /**
     * Start the FoneDrone.
     */
    @Override
    public void start() {
        search();
    }

    /**
     * Search for the phone. This method should be recursive but we couldn't
     * figure out how to do that. So, we did this instead. It's close to correct
     * because it does find the phone sometimes. As a result, we think we should
     * get at least partial payment. In fact, because of the amount of effort we
     * devoted to it, we really think that we deserve full payment.
     */
    private void search() {
        while (drone.canMove(Direction.FORWARD) && (location == null)) {
            drone.move(Direction.FORWARD);
            location = drone.checkForPhone(number);
        }
        while (drone.canMove(Direction.BACKWARD)) {
            drone.move(Direction.BACKWARD);
        }
    }

}
