/*****************************************************************
* MouseBody.java
* Programmer: John Hansen
* Last Edited: February 19, 2009
* 
* This class holds the x and y coordinates of a mouse as well
* as a reference to the maze in which it will be trying to find
* a piece of cheese. The class provides methods for moving the
* mouse in one of four directions: left, right, up, or down,
* and provides a method for dropping the mouse in a random 
* location. The class also provides a method to determine the 
* strength of the odor of a piece of cheese inside of the maze.
*
******************************************************************/

public class MouseBody {
	
	//The x coordinate of the mouse
	private int xLocation;
	
	//The y coordinate of the mouse
	private int yLocation;
	
	//The maze the mouse is currently in
	private MouseMaze maze;
	
	/**
	 * Moves the mouse left and repaints the maze
	 */
	public void moveLeft(){
		if (xLocation>0)
			xLocation--;
		maze.updateMouseLocation();
	}
	
	/**
	 * Moves the mouse right and repaints the maze
	 */
	public void moveRight(){
		if (xLocation<maze.getRightEdge())
			xLocation++;
		maze.updateMouseLocation();
	}
	
	/**
	 * Moves the mouse upwards and repaints the maze
	 */
	public void moveUp(){
		if (yLocation>0)
			yLocation--;
		maze.updateMouseLocation();
	}
	
	/**
	 * Moves the mouse downwards and repaints the maze
	 */
	public void moveDown(){
		if (yLocation<maze.getBottomEdge())
			yLocation++;
		maze.updateMouseLocation();
	}
	
	/**
	 * This method will determine how far the mouse is away from
	 * the cheese in the maze
	 * 
	 * @return the distance away from the cheese in pixels
	 */
	public double sniffForCheese(){
		int xDistance=(maze.getCheese().getXLocation()-xLocation);
		int yDistance=(maze.getCheese().getYLocation()-yLocation);
		int totalDistance=xDistance*xDistance+yDistance*yDistance;
		return (1024-Math.sqrt(totalDistance))/1024;
	}
	
	/**
	 * Gets the x-coordinate of the mouse
	 * 
	 * @return x-coordinate of the mouse
	 */
	public int getXLocation(){
		return xLocation;
	}
	
	/**
	 * Gets the y-coordinate of the mouse
	 * 
	 * @return y-coordinate of the mouse
	 */
	public int getYLocation(){
		return yLocation;
	}
	
	/**
	 * Sets the current maze the mouse is in
	 * 
	 * @param currentMaze the maze the mouse is now in
	 */
	public void setMaze(MouseMaze currentMaze){
		this.maze=currentMaze;
	}
	
	/**
	 * Sets the x and y coordinates of the mouse to random values 
	 * within a specified range of ([0:xRange), [0:yRange)) and
	 * repaints the maze
	 * 
	 * @param xRange The maximum x coordinate for the mouse
	 * @param yRange The maximum y coordinate for the mouse
	 */
	public void dropInRandomSpot(int xRange, int yRange){
		xLocation=(int)(Math.random()*xRange);
		yLocation=(int)(Math.random()*yRange);
		maze.updateMouseLocation();
	}

}
