File: js/classes/pieces/Bishop.js
/**
module contains classes of pieces
@module Pieces
**/
/**
* A Bishop class, represents a Bishop piece
* @class Bishop
* @constructor
* @param {} color bishop's color
* @param {} type type of the piece, e.g. "Bishop"
* @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 Bishop(color, type, X, Y, id) {
/**
* Bishop's color
* @property color
* @type String
*/
this.color = color;
/**
* Bishop'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;
/**
* Bishop's ID
* @property ID
* @type Number
*/
this.ID = id;
/**
* notation symbol
* @property notationName
* @type String
*/
this.notationName = "B";
/**
* 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/wbishop.png";
} else {
return "images/pieces/bbishop.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 = getBishopLegalMoves(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 getBishopCoveredFields(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;
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 "B";
} else {
return "b";
}
}
}