UNPKG

@runox-game/game-engine

Version:
38 lines (37 loc) 1.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Deck = void 0; var Deck = /** @class */ (function () { function Deck() { this.cards = []; } Deck.prototype.addCards = function (cards) { var _a; (_a = this.cards).push.apply(_a, cards); }; Deck.prototype.shuffle = function () { var index = this.cards.length, temporaryValue, randomIndex; // mientras queden elementos a mezclar while (0 !== index) { // seleccionar un elemento sin mezclar randomIndex = Math.floor(Math.random() * index); index -= 1; // e intercambiarlo con el elemento actual temporaryValue = this.cards[index]; this.cards[index] = this.cards[randomIndex]; this.cards[randomIndex] = temporaryValue; } }; Deck.prototype.takeCard = function () { if (!this.cards.length) { throw new Error('No hay cartas disponibles en el mazo'); } var card = this.cards.shift(); if (!card) { throw new Error('No ha sido posible tomar cartas del mazo'); } return card; }; return Deck; }()); exports.Deck = Deck;