API Docs for:
Show:

File: js/classes/pieces/Rook.js

/**
module contains classes of pieces
@module Pieces
**/ 

/**
* A Rook class, represents a Bishop piece
* @class Rook
* @constructor
* @param {} color 	rook's color
* @param {} type 	type of the piece, e.g. "Rook" 
* @param {} X 		x coordinate on the board (0-7), 0 represents 'a' file, 7 represents 'h' file 
* @param {} Y 		y coordinate on the board (0-7), 0 represents 8-th rank, 7 represnts 1-st rank
* @param {} id 		id of the piece
*/
function Rook(color, type, X, Y, id) {
    /**
 	* Rook's color
 	* @property color
 	* @type String
 	*/
    this.color  = color;
	
	/**
 	* Rook's type
 	* @property type
 	* @type String
 	*/
    this.type   = type;
	
	/**
 	* x coordinate
 	* @property X
 	* @type Number
 	*/
    this.X      = X;
	
	/**
 	* y coordinate
 	* @property Y
 	* @type Number
 	*/
    this.Y      = Y;
	
	/**
 	* Rook's ID
 	* @property ID
 	* @type Number
 	*/
	this.ID 	= id;
	
	/**
 	* notation symbol
 	* @property notationName
 	* @type String
 	*/
	this.notationName 	= "R";
	
	/**
     * get relative path to the piece image
     * @method getImageSource
     * @return {String} path to the piece image
     */
    this.getImageSource = function (){
        
        if(this.color == "white") {
            return "images/pieces/wrook.png";
        } else {
            return "images/pieces/brook.png";
        }
    }
    
	/**
     * get piece legal moves
     * @method getLegalMoves
     * @return {Array} an array of (x,y) coordinates represents a legal moves for a piece
     */
    this.getLegalMoves = function() {
		legalMoves = getRookLegalMoves(this.X, this.Y, this.color);
        return preventCheck(this, legalMoves);
    }
    
	/**
     * get piece covered fields
     * @method getCoveredFields
     * @return {Array} an array of (x,y) coordinates represents a set of fields, covered by a piece 
     */
    this.getCoveredFields = function() {
        return getRookCoveredFields(this.X, this.Y, this.color);
    }
	
	/**
	 * moves piece to a new field
	 * @method move
	 * @param {Number} x x coordinate of destination
	 * @param {Number} y y coordinate of destination
	 * @return {Object} object represents a summary of the move 
	 */
	this.move = function(x, y) {
		
        if(!confirmMove(x,y,this)) return;
		
		var origin = {x:this.X,y:this.Y};
		var destination = {x:x,y:y};

		if(this.X == 0 && this.Y == 0) board.blackCanCastleLong 	= "false";
		if(this.X == 7 && this.Y == 0) board.blackCanCastleShort 	= "false";
		if(this.X == 7 && this.Y == 7) board.whiteCanCastleShort 	= "false";
		if(this.X == 0 && this.Y == 7) board.whiteCanCastleLong 	= "false";
        
        return finishMove(x,y,this);
	}
	
	/**
	 * get notation symbol of the piece
	 * @method getNotationSymbol
	 * @return {String} notation symbol
	 */
	this.getNotationSymbol = function() {
		if(this.color == "white") {
			return this.notationName.toUpperCase();
		} else {
			return this.notationName.toLowerCase();
		}
	}
}