@runox-game/game-engine
Version:
RunoX game engine
57 lines (56 loc) • 1.98 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Hand = void 0;
var Hand = /** @class */ (function () {
function Hand() {
this.cards = [];
}
Object.defineProperty(Hand.prototype, "valid", {
get: function () {
return (this.cards !== undefined &&
!!this.cards.reduce(function (total, x) { return x.valid && total; }, true));
},
enumerable: false,
configurable: true
});
Object.defineProperty(Hand.prototype, "score", {
get: function () {
return this.cards.reduce(function (score, card) {
score += card.score;
return score;
}, 0);
},
enumerable: false,
configurable: true
});
Hand.prototype.addCard = function (card) {
this.cards.push(card);
};
Hand.prototype.addCards = function (cards) {
var _a;
(_a = this.cards).push.apply(_a, cards);
};
Hand.prototype.removeCard = function (card) {
if (!card) {
throw new Error("La mano del jugador no posee cartas");
}
var cardIndex = this.cards.findIndex(function (handCard) { return handCard.id === card.id; });
if (cardIndex === -1) {
throw new Error("La mano del jugador no posee la carta: " + card.id);
}
this.cards.splice(cardIndex, 1);
};
Hand.prototype.removeCards = function (cards) {
for (var i = 0; i < cards.length; i++) {
this.removeCard(cards[i]);
}
};
Hand.prototype.hasCard = function (value, color) {
if (!color) {
return this.cards.some(function (handCard) { return handCard.value === value; });
}
return this.cards.some(function (handCard) { return handCard.value === value && handCard.color === color; });
};
return Hand;
}());
exports.Hand = Hand;