//***********************************
//
// Alex Apostol
//
// Cookies.
//
//
//************************************

import java.applet.*;// used for applets
import java.awt.*;// if you use any kind of graphics
import java.io.*;// if you use any kind of I/O
import java.awt.event.*;

public class Cookie
{

    int size;
    int flavor; //0 is a chocolate.  1 is cinnamon. 2 is an oreo, 3 is raisin.
    int id;
    //***************************************
    //     CONSTRUCTORS
    //***************************************
    /**
     * Cookie Constructor.
     *  Flavor 0 makes a chocolate cookie.
     *  Flavor 1 makes a lemon cookie.
     *  flavor 2 makes an oreo.
     *  Flavor 3 makes a raisin cookie.
     * @param s size of cookie.
     *        t type of cookie.
     *        i id of cookie.
     */
    Cookie(int s, int f, int i )
    {
	size = s;
	flavor = f % 4;
	id = i;
    }

    /*
     * Default constructor, sets everything to 0
     * So the cookie exists only in theory until size is set.
     */
    Cookie()
    {
	id =0;
	flavor = 0;
	size = 0;
    }

    //***************************************
    //     SETFLAVOR
    //***************************************
    /**
     * changes the cookie type.
     *  Flavor 0 makes a chocolate cookie.
     *  Flavor 1 makes a lemon cookie.
     *  flavor 2 makes an oreo.
     *  Flavor 3 makes a raisin cookie.
     * @param f flavor of cookie.
     */
    public void setFlavor(int f)
    {
	flavor = f % 4;
    }


    //***************************************
    //     SetID
    //***************************************
    /**
     * changes the cookie ID.
     * @param i new ID  of cookie.
     */
    public void setID(int i)
    {
	id=i;
    }

    //***************************************
    //     SetSize
    //***************************************
    /**
     * changes the cookie size.
     * @param s size of cookie.
     */
    public void setSize(int s)
    {
	size = s;
    }

    //***************************************
    //     GETFLAVOR
    //***************************************
    /**
     *  Flavor 0 makes a chocolate cookie.
     *  Flavor 1 makes a lemon cookie.
     *  flavor 2 makes an oreo.
     *  Flavor 3 makes a raisin cookie.
     *  @return the type of cookie as an int 0-3.
     */
    public int getFlavor ()
    {
	return flavor;
    }

    //***************************************
    //     GETSIZE
    //***************************************
    /**
     * @return size of cookie in pixels.
     */
    public int getSize()
    {
	return size;
    }

    //**************************************
    //  GETHEIGHT
    //
    /***************************************
     * @return the height of the cookie.
     */
    public int getHeight()
    {
	switch(flavor)
	    {
	    case 0:
		return 15;
	    case 1:
		return 40;
	    case 2:
		return 25;
	    case 3:
		return 15;
	    }
	return 15;
    }

    //***************************************
    //     INCREASESIZE
    //***************************************
    /**
     * Incriments the size of the cookie.
     */
    public void increaseSize()
    {
	size++;
    }

    //***************************************
    //     PRINT
    //***************************************
    /**
     * Prints the cookie info the javasun console.
     */
    public void print()
    {
	switch(flavor)
	    {
	    case 0: System.out.print("size="+size+" chocolate cookie, id:" +id); break;
	    case 1: System.out.print("size="+size+" lemon cookie, id:" +id); break;
	    case 2: System.out.print("size="+size+" OREO! id: "+id); break;
	    case 3: System.out.print("size="+size+" raisin cookie. id:" +id); break;
	    default: flavor=0; System.out.print(" strange cookie."); break;
	    }
    }

    //***************************************
    //     DRAW
    //***************************************
    /**
     * Paints a cookie to the canvas at the specified location
     * @param x x location of the upper right corner
     *        y y location of the upper right corner
     */
    public void draw (Graphics g, int x, int y)
    {
	int s=5*size;
 	Color c = new Color (128, 64, 0);
	switch(flavor)
	    {
 	    case 0:
	 	g.setColor(c);
 		g.fillOval(x, y, s, 15);
	 	break;
	    case 1:
		g.setColor(Color.orange);
		g.fillRect(x, y, s, 40);
		break;
	    case 2:
		g.setColor(Color.red);
		g.fillOval(x, y+10, s, 15);
		g.setColor(Color.white);
		g.fillOval(x+5, y+5, s-10, 15);
		g.setColor(Color.red);
		g.fillOval(x, y, s, 15);
		break;
	    case 3:
		g.setColor(Color.blue);
		g.fillOval(x,y, s, 15);
	    default:
		g.setColor(Color.green);
		g.fillOval(x, y, s, 15);
		break;
	    }

    }

}
