import java.awt.*;
import java.applet.*;
/*
 *
 * ball
 *
 */
class ball 
{



	final int LEFT=0, RIGHT = 1, UP = 2, DOWN = 3;
	final int LEFT_WALL = 10, RIGHT_WALL = 300, TOP_WALL = 10, BOTTOM_WALL = 220;
	int x_pos,  y_pos, size;
	int dir_x, dir_y;
	int xinc = 10, yinc = 8;
	Graphics g;
	paddle p;
	Applet owner;

	void setApplet (Applet a)
	{
		owner = a;
	}
	void setPaddle(paddle pp) 
	{
		p = pp;
	}

	void setGraphics(Graphics gr)
	{
		g = gr;
	}
	 


	void move() 
	{
		switch (dir_x)
		{
		case LEFT:
			  {
				  x_pos -= xinc;
				  if (x_pos < LEFT_WALL)
				  {
					  x_pos = LEFT_WALL;
					  dir_x = RIGHT;
				  }
			  }
			  break;
		case RIGHT:
			{
				//paddle-ball intersection goes here
				x_pos += xinc;
				if (x_pos > RIGHT_WALL)
				  {
					if ((y_pos > p.getBottom()) || (y_pos < p.getTop()))
					{
						//die
						owner.showStatus("You missed the ball!");
						x_pos = RIGHT_WALL;
						dir_x = LEFT;

					}
					else
					{
					  x_pos = RIGHT_WALL;
					  dir_x = LEFT;
					  owner.showStatus("You hit it! Good job!");

					}
				  }

			}
			break;
		}
		switch (dir_y)
		{
		case UP:
			  {
				  y_pos -= yinc;
				  if (y_pos < TOP_WALL)
				  {
					  y_pos = TOP_WALL;
					  dir_y = DOWN;
				  }

			  }
			  break;
		case DOWN:
			{
				y_pos += yinc;
				if (y_pos > BOTTOM_WALL)
				  {
					  y_pos = BOTTOM_WALL;
					  dir_y = UP;
				  }


			}
			break;
		}
		
	}



	 ball (int x, int y, int mysize)
	 {
		 x_pos = x;
		 y_pos = y;
		 dir_x = LEFT;
		 dir_y = UP;
		 size = mysize;
		 
	 }

	 void set_size(int x)
	 {
		 size = x;
	 }

	 void draw ()
	 {
		 //overlay with background here
		 g.setColor(Color.white);
		 g.fillOval( x_pos, y_pos, size, size);
		 move();
	  	 g.setColor(Color.black);
		 g.fillOval( x_pos, y_pos, size, size);

	 }

	 void move (int x, int y)
	 {
		 
		 x_pos = x;
		 y_pos = y;
		 
	 }
}

