UNPKG

@runox-game/game-engine

Version:
86 lines (85 loc) 3.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Card = void 0; var id_generator_helper_1 = require("../utils/id-generator.helper"); var values_model_1 = require("./values.model"); var Card = /** @class */ (function () { function Card(value, color, id) { if (values_model_1.isSpecial(value) && color) { throw new Error("La carta \"" + value + "\" no puede tener el color \"" + color + "\""); } this.id = id || id_generator_helper_1.generateUniqueId(); this.sprite = color ? value + "--" + color : value; this.value = value; this.color = color; } Object.defineProperty(Card.prototype, "valid", { get: function () { return (this.id !== undefined && this.sprite !== undefined && this.value !== undefined); }, enumerable: false, configurable: true }); Object.defineProperty(Card.prototype, "score", { get: function () { switch (this.value) { case values_model_1.Value.PLUS_TWO: case values_model_1.Value.SKIP: case values_model_1.Value.REVERSE: return 20; case values_model_1.Value.WILDCARD: case values_model_1.Value.PLUS_FOUR: return 50; case values_model_1.Value.ONE: return 1; case values_model_1.Value.TWO: return 2; case values_model_1.Value.THREE: return 3; case values_model_1.Value.FOUR: return 4; case values_model_1.Value.FIVE: return 5; case values_model_1.Value.SIX: return 6; case values_model_1.Value.SEVEN: return 7; case values_model_1.Value.EIGHT: return 8; case values_model_1.Value.NINE: return 9; case values_model_1.Value.ZERO: return 0; default: return 0; } }, enumerable: false, configurable: true }); Card.prototype.isSpecialCard = function () { return values_model_1.isSpecial(this.value); }; Card.prototype.hasEffects = function () { return (this.isSpecialCard() || this.value === values_model_1.Value.PLUS_TWO || this.value === values_model_1.Value.REVERSE || this.value === values_model_1.Value.SKIP); }; Card.prototype.setColor = function (color) { this.color = color; }; Card.prototype.isPlayable = function (otherCard) { if (this.isSpecialCard()) { return true; } if (!this.color || !otherCard.color) { throw new Error('Ambas cartas deben tener definido un color para poder compararlas'); } return otherCard.value === this.value || otherCard.color === this.color; }; return Card; }()); exports.Card = Card;