import java.awt.*;

/**
  *This represents those ArcadeGamePieces that move
  */
public abstract class MovablePiece extends ArcadeGamePiece{
	protected Velocity _currentVelocity;
	protected BricklesView _theView;
	protected Point _leadingPoint;
	
	/**
	  *Constructor initializes the attributes of the class
	  *@param fieldPtr the PlayingField that contains the MovablePiece
	  *@param initialLocation the starting position for the MovabalePiece
	  *@param initalVelocity the Velocity of the piece when it is created
	  */
	public MovablePiece(PlayingField fieldPtr, Point initialLocation,Velocity initialVelocity){
		super(fieldPtr, initialLocation);
		_currentVelocity = initialVelocity;
	}

	/**
	  *@return the leadingPoint instead of the currentPosition
	  *
	  */
	public Point getPosition(){
		return _leadingPoint;
	}

	/**
	  *@return the velocity of the MovablePiece
	  */
	public Velocity getVelocity(){
		return _currentVelocity;
	}

	/**
	  *Sets the velocity
	  *@param newVelocity the Velocity to be set
	  */
	public void setVelocity(Velocity newVelocity){
		_currentVelocity = newVelocity;
	}

	/**
	  *Behavior in response to tick of the timer 
	  *post: The object has been moved and if a collision has occurred an
	  *exception has been thrown
	  */
	public void tick(){
		this.move();
		try{
			_fieldPtr.moved(this);
		}
		catch(Collision aCollision){
			aCollision.occur();
		}
	}

	/**
	  *abstract specification for the move behavior
	  *post: The MovablePiece has been moved the distance indicated
	  *by the velocity
	  */
	public abstract void move();

	/**
	  *Provides a no-op for the general collision methd
	  */
	public void collideWith(ArcadeGamePiece aPiece,Point aPoint){}

	/**
	  *Abstract specification of colliding with the Paddle
	  *post: the velocity has been changed
	  */
	public abstract void collideWithPaddle(Paddle aPaddle,Point aPoint);

	/**
	  *Abstract specification of colliding with the Puck
	  *post: the velocity has been changed 
	  */
	public abstract void collideWithPuck(Puck aPuck,Point aPoint);

	/**
	  *reverses the Y component of the piece's velocity
	  */
	public void reverseY(){
		_currentVelocity.reverseY();
	}

	/**
	  *reverses the X component of the piece's velocity
	  */
	public void reverseX(){
		_currentVelocity.reverseX();
	}
}
