Piece.java 2.31 KB
/**
 *Board and movement of pieces
 *@author arghavan soleymanpour
 *@version 2.0
 */
package Pieces;

import Main.Board;

import java.util.ArrayList;

public abstract class Piece implements Cloneable {
    private int x;
    private boolean isWhite;
    private int y;
    private Board board;
    public Piece(int x , int y , boolean isWhite , Board board){
        this.x = x;
        this.y = y;
        this.isWhite = isWhite;
        this.board = board;
    }
    /**
     * This is the method for Color of Piece
     * @return isWhite.
     */
    public boolean isWhite(){
        return isWhite;
    }
    /**
     * This is the method for Color of Piece
     * @return isBlack.
     */
    public boolean isBlack(){
        return !isWhite;
    }
    /**
     * This is the method for x-axis of Piece
     * @return x-axis.
     */
    public int getX() {
        return x;
    }

    public Board getBoard() {
        return board;
    }

    /**
     * This is the method for set x-axis of Piece
     * @param x x-axis
     * @return void.
     */
    public void setX(int x) {
        this.x = x;
    }

    /**
     * This is the method for y-axis of Piece
     * @return y-axis.
     */
    public int getY() {
        return y;
    }
    /**
     * This is the method for set y-axis of Piece
     * @param y y-axis
     * @return void.
     */
    public void setY(int y) {
        this.y = y;
    }
    /**
     * This is the method for validate move of piece
     * @param dx destination x
     * @param dy destination y
     * @return is a Valid move.
     */
    abstract public boolean isValidMove(int dx,int dy);
    /**
     * This is the method for list of valid move of piece
     * @return list of valid moves of piece.
     */
    abstract public ArrayList<int[]> moves();
    /**
     * This is the method for check outside of piece
     * @param dx destination x.
     * @param dy destination y.
     * @return is destination outside?.
     */
    public boolean isOutside(int dx, int dy){
        if (dx < 0 || dx > 8 || dy < 0 || dy > 8)
            return false;
        return true;
    }
    public Object clone(){
        try {
            return super.clone();
        } catch (CloneNotSupportedException e) {
            System.err.println("Clone Error");
            e.printStackTrace();
        }
        return null;
    }
}