UNPKG

cardation

Version:

fundation of card games, card model

70 lines (69 loc) 2.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const CardError_1 = require("../../error/CardError"); const SuitCard_1 = require("./SuitCard"); const utils_1 = require("../serialization/utils"); const notationMap = { j: 11, J: 11, q: 12, Q: 12, k: 13, K: 13, }; // eslint-disable-next-line no-sparse-arrays const notationArray = [, , , , , , , , , , , 'J', 'Q', 'K']; class FaceCard extends SuitCard_1.default { _suit; _rank; _point; constructor(suit, rank, point) { super(); this._suit = suit; if (typeof rank == 'string') { rank = notationMap[rank]; } if (typeof rank != 'number') { throw new CardError_1.default('[FaceCard][constructor]: rank should be one of the elements of ["J", "Q", "K", "j", "q", "k", "11", "12", "13"]!'); } if (rank < 11 || rank > 13) { throw new CardError_1.default('[FaceCard][constructor]: rank should be in the range from 11 to 13!'); } this._rank = rank; if (point === undefined) { this._point = this._rank; } else { if (Number.isNaN(+point)) { throw new CardError_1.default(`[FaceCard][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; } setPoint(point) { this._point = point; } getCardSuit() { return this._suit; } toString() { return `${this._suit.getIcon()}${notationArray[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 = FaceCard;