@sillyal/dominion
Version:
Representation of Dominion, a deck-building card game created by Donald X. Vaccarino and published by Rio Grande Games.
142 lines • 4.6 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var utils_1 = require("./utils");
var Player = /** @class */ (function () {
function Player(deck, discard, hand) {
this.reacting = false;
this.discard = [];
this.deck = [];
this.setAside = [];
this.hand = [];
this.played = [];
this.deck = deck;
this.discard = discard;
this.hand = hand;
}
Player.prototype.isPlaying = function () {
return this.pool !== undefined;
};
Player.prototype.setup = function (pool) {
this.pool = pool || { actions: 1, buys: 1, coins: 0 };
};
Player.prototype.updatePool = function (pool) {
if (this.pool) {
this.pool.actions += pool.actions;
this.pool.buys += pool.buys;
this.pool.coins += pool.coins;
}
};
Player.prototype.canPlayActionCard = function () {
return this.pool !== undefined && this.pool.actions > 0;
};
Player.prototype.canBuyCard = function () {
return this.pool !== undefined && this.pool.buys > 0;
};
Player.prototype.getCoins = function () {
return this.pool ? this.pool.coins : 0;
};
Player.prototype.cleanup = function () {
this.pool = undefined;
this.discard = this.discard.concat(this.hand, this.played, this.setAside);
this.hand = [];
this.played = [];
this.setAside = [];
};
Player.prototype.drawNCards = function (n) {
if (this.deck.length < n) {
this.shuffle();
}
var numOfCardsToDraw = Math.min(n, this.deck.length);
var cards = this.deck.slice(0, numOfCardsToDraw);
this.hand = this.hand.concat(cards);
this.deck = this.deck.slice(numOfCardsToDraw);
return cards;
};
Player.prototype.playACard = function (card) {
var index = this.hand.indexOf(card);
if (index < 0) {
return;
}
var played = this.hand.splice(index, 1)[0];
this.played = this.played.concat([played]);
return played;
};
Player.prototype.discardACard = function (card) {
var index = this.hand.indexOf(card);
if (index < 0) {
return;
}
var toDiscard = this.hand.splice(index, 1)[0];
this.discard = this.discard.concat([toDiscard]);
return toDiscard;
};
Player.prototype.moveBackADiscardedCard = function (card) {
var index = this.discard.indexOf(card);
if (index < 0) {
return;
}
var toMoveBack = this.discard.splice(index, 1)[0];
this.deck = [toMoveBack].concat(this.deck);
return toMoveBack;
};
Player.prototype.putACardFromHandOntoDeck = function (card) {
var index = this.hand.indexOf(card);
if (index < 0) {
return;
}
var toMove = this.hand.splice(index, 1)[0];
this.deck = [toMove].concat(this.deck);
return toMove;
};
Player.prototype.trashACard = function (card) {
var index = this.hand.indexOf(card);
if (index < 0) {
return;
}
return this.hand.splice(index, 1)[0];
};
Player.prototype.setAsideACard = function (card) {
var index = this.hand.indexOf(card);
if (index < 0) {
return;
}
var setAside = this.hand.splice(index, 1)[0];
this.setAside = this.setAside.concat([setAside]);
return setAside;
};
Player.prototype.buyACard = function (card) {
this.discard = this.discard.concat([card]);
};
Player.prototype.gainACard = function (card) {
this.discard = this.discard.concat([card]);
};
Player.prototype.gainACardToHand = function (card) {
this.hand = this.hand.concat([card]);
};
Player.prototype.getDiscard = function () {
return this.discard;
};
Player.prototype.getDeck = function () {
return this.deck;
};
Player.prototype.getSetAside = function () {
return this.setAside;
};
Player.prototype.getHand = function () {
return this.hand;
};
Player.prototype.getPlayed = function () {
return this.played;
};
Player.prototype.shuffle = function () {
if (this.discard.length === 0) {
return;
}
utils_1.shuffle(this.discard);
this.deck = this.deck.concat(this.discard);
this.discard = [];
};
return Player;
}());
exports.Player = Player;
//# sourceMappingURL=player.js.map