/*
 * Created on Nov 22, 2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package jone;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Point2D;
import java.awt.*;
import java.util.Random;
/**
 * @author brian
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class GrassPatch extends Critter
{
	static int maxHealth = 1;
	static double radius = .1;
	public GrassPatch()
	{	
		this.foodSupplyDensity = 2;
	}
	/* (non-Javadoc)
	 * @see jone.Critter#draw()
	 */
	public void draw() {
		// TODO Auto-generated method stub
		
	}

	/* (non-Javadoc)
	 * @see jone.Critter#respawn()
	 */
	public void respawn(Critter [] critters) {
		// TODO Auto-generated method stub
		super.respawn(critters);
		//this.position = new Point2D.Double(rand.nextDouble(),rand.nextDouble());
		this.health = maxHealth;
	}

	public double getRadius()
	{
		return GrassPatch.radius;
	}
	/* (non-Javadoc)
	 * @see jone.Critter#init()
	 */
	public void init() {
		// TODO Auto-generated method stub
		
	}
	
	
	
	public double amountLeft()
	{
		return health;
	}
	
	protected int numSheepEating;
	protected double foodSupplyDensity;
	
	public double deplete(Sheep s)
	{
		if(this.position.distance(s.getPosition()) < 
				/* s.getRadius() + */ GrassPatch.radius)
		{
			//health /= 2; //-= this.foodSupplyDensity;
			return this.health;
		}
		Random rand = RandomSingleton.getDefaultInstance();
		if(rand.nextDouble() < .001) {
			//this.respawn();
		}
		return 0.0;
	}
	
	public static double xd = Math.cos(Math.PI/4);
	public static double yd = Math.sin(Math.PI/4);
	/* (non-Javadoc)
	 * @see jone.Critter#draw(java.awt.Graphics)
	 */
	public void draw(Graphics g) {
		// TODO Auto-generated method stub
		
		ArenaPanel ap = ArenaPanel.getInstance();
		
		Graphics2D g2d = (Graphics2D) g;
	    // pull info out of graphics to know the start position of drawing
		/* x and y need to be the upper left hand corner of the rectangle */
		int x = (int) ((this.position.x - xd*GrassPatch.radius) * ap.width()); //+ ap.startX();
		int y = (int) ((this.position.y - yd*GrassPatch.radius) * ap.height());
		int r = (int) (GrassPatch.radius * ap.width());
		if(Arena.debug)
		{
			//Arena.logger.debug("printing grass at x = " + x + " y = " + y);
		}
		
		g2d.setPaint(Color.black); 
		g2d.setStroke(new BasicStroke(2));
		g2d.drawOval(x,y,r,r);
	}
	/* (non-Javadoc)
	 * @see jone.Critter#getWeight()
	 */
	public double getWeight() {
		// TODO Auto-generated method stub
		return 0;
	}
}
