cardation
Version:
fundation of card games, card model
55 lines (54 loc) • 1.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const CardError_1 = require("../../error/CardError");
const SuitCard_1 = require("./SuitCard");
const utils_1 = require("../serialization/utils");
class NumberCard extends SuitCard_1.default {
_suit;
_point;
_rank;
constructor(suit, rank, point) {
super();
this._suit = suit;
rank = +rank;
if (rank < 2 || rank > 10) {
throw new CardError_1.default('[NumberCard][constructor]: rank should be in the range from 2 to 10!');
}
this._rank = rank;
if (point === undefined) {
this._point = this._rank;
}
else {
if (Number.isNaN(+point)) {
throw new CardError_1.default(`[NumberCard][constructor]: point is expected to be a number but get the type ${typeof point}!`);
}
this._point = +point;
}
}
getCardId() {
return `${this._suit.getShortName()}${this._rank}.${this._point}`;
}
getPoint() {
return this._point;
}
getRank() {
return this._rank;
}
getCardSuit() {
return this._suit;
}
setPoint(point) {
this._point = point;
}
toString() {
return `${this._suit.getIcon()}${this._rank}`;
}
/**
* Convert the card to a colored string, which can be printed to the console.
* @returns {string}
*/
getGraph() {
return (0, utils_1.getGraph)(this);
}
}
exports.default = NumberCard;