import java.awt.Graphics;

///////////////////////////////////////////////////////////////////////////////
//
// Line - A rather meager implementation of a Line object.
//
///////////////////////////////////////////////////////////////////////////////

public class Line {
	int X1, // The X location of the first point defining this line.
			X2, // The X location of the second point defining this line.
			Y1, // The Y location of the first point defining this line.
			Y2, // The Y location of the second point defining this line.
			XBound, // The highest possible X location.
			YBound, // The highest possible Y location.
			X1Vector, // The X Vector of the first point defining this line.
			Y1Vector, // The Y Vector of the first point defining this line.
			X2Vector, // The X Vector of the second point defining this line.
			Y2Vector; // The Y Vector of the second point defining this line.

	// Constructor for this class.
	Line(int a, int b, int c, int d) {
		X1 = a;
		Y1 = b;
		X2 = c;
		Y2 = d;
	}

	// Tell the line what boundaries it has to work in.
	public void SetBoundaries(int X, int Y) {
		XBound = X;
		YBound = Y;
	}

	// Move the line to another locale.
	public void SetLine(int a, int b, int c, int d) {
		X1 = a;
		Y1 = b;
		X2 = c;
		Y2 = d;
	}

	// Display this line on a given Graphics structure.
	public void DrawLine(Graphics g) {
		g.drawLine(X1, Y1, X2, Y2);
	}

	// Set the vectors, ie: give the line a push.
	public void Push(int X1V, int Y1V, int X2V, int Y2V) {
		X1Vector = X1V;
		Y1Vector = Y1V;
		X2Vector = X2V;
		Y2Vector = Y2V;
	}

	// Apply the vectors and allow the line to drift withing the
	// given boundaries.
	public void Drift() {
		if ((X1 + X1Vector) > XBound || (X1 + X1Vector < 0))
			X1Vector *= -1;

		if ((Y1 + Y1Vector) > YBound || (Y1 + Y1Vector < 0))
			Y1Vector *= -1;

		if ((X2 + X2Vector) > XBound || (X2 + X2Vector < 0))
			X2Vector *= -1;

		if ((Y2 + Y2Vector) > YBound || (Y2 + Y2Vector < 0))
			Y2Vector *= -1;

		X1 += X1Vector;
		Y1 += Y1Vector;
		X2 += X2Vector;
		Y2 += Y2Vector;
	}
}

