File: js/classes/pieces/Queen.js
/**
module contains classes of pieces
@module Pieces
**/
/**
* A Queen class, represents a Knight piece
* @class Queen
* @constructor
* @param {} color queen's color
* @param {} type type of the piece, e.g. "Queen"
* @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 Queen(color, type, X, Y, id) {
/**
* Queen's color
* @property color
* @type String
*/
this.color = color;
/**
* Queen'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;
/**
* Queen's ID
* @property ID
* @type Number
*/
this.ID = id;
/**
* notation symbol
* @property notationName
* @type String
*/
this.notationName = "Q";
/**
* 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/wqueen.png";
} else {
return "images/pieces/bqueen.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() {
var legalMoves = [];
legalMoves = legalMoves.concat(getBishopLegalMoves(this.X, this.Y, this.color));
legalMoves = legalMoves.concat(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() {
var coveredFields = [];
coveredFields = coveredFields.concat(getBishopCoveredFields(this.X, this.Y, this.color));
coveredFields = coveredFields.concat(getRookCoveredFields(this.X, this.Y, this.color));
return coveredFields;
}
/**
* 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 this.notationName.toUpperCase();
} else {
return this.notationName.toLowerCase();
}
}
}