// Arup Guha
// 2/24/2026
// Base class used in my "Pacman" game.
// Edited on 3/8/2026 for Abstract class lecture.

abstract class Piece {

	protected Position loc;
	protected Position dir;
	
	// Constructor places the piece at cur, and the direction vector change.
	public Piece(Position cur, Position change) {
		loc = cur;
		dir = change;
	}
	
	// Returns true iff a move of this objects keeps it in the specified bounds.
	public boolean wouldStayInBounds(int minX, int maxX, int minY, int maxY) {
		Position tmp = loc.wouldMoveBy(dir);
		return tmp.inbounds(minX, maxX, minY, maxY);
	}

	// Returns true iff the current location of this Piece is within
	public boolean inbounds(int minX, int maxX, int minY, int maxY) {
		return loc.inbounds(minX, maxX, minY, maxY);
	}
	
	// Returns a string representation of this Position.
	public String toString() {
		return loc.toString();
	}
	
	// Executes a single move of this Piece.
	public void move() {
		loc.moveBy(dir);
	}
	
	// Reset dir to mydir.
	public void setDir(Position mydir) {
		dir = mydir;
	}
	
	public void negateDir() {
		dir.negate();
	}
	
	public void incX() {
		setDir(new Position(0,1));
	}
	
	public void decX() {
		setDir(new Position(0,-1));
	}
	
	public void decY() {
		setDir(new Position(-1,0));
	}
	
	public void incY() {
		setDir(new Position(1,0));
	}
	
	// Returns where this Piece is.
	public Position getLoc() {
		return loc;
	}
	
	/*** This is what makes this class abstract. All classes
	     that inherit from this one must have a single character code
		 that is returned by a getCode() method.
	***/
	public abstract char getCode();
	
}