UNPKG

@gamepark/rules-api

Version:

API to implement the rules of a board game

32 lines 1.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StakingStrategy = void 0; var PositiveSequenceStrategy_1 = require("./PositiveSequenceStrategy"); /** * This strategy will only work on items with the same location.x and location.y, to maintain a positive sequence on location.z, * for example to easily stack scoring pawns when they are on the same spot. */ var StakingStrategy = /** @class */ (function () { function StakingStrategy() { this.delegate = new PositiveSequenceStrategy_1.PositiveSequenceStrategy('z'); } StakingStrategy.prototype.addItem = function (material, item) { this.delegate.addItem(material.location(function (l) { return l.x === item.location.x && l.y === item.location.y; }), item); }; StakingStrategy.prototype.moveItem = function (material, item, index) { var itemBefore = material.getItem(index); if (itemBefore.location.x === item.location.x && itemBefore.location.y === itemBefore.location.y) { this.delegate.moveItem(material, item, index); } else { this.delegate.removeItem(material.index(function (i) { return i !== index; }).location(function (l) { return l.x === itemBefore.location.x && l.y === itemBefore.location.y; }), itemBefore); this.delegate.addItem(material.location(function (l) { return l.x === item.location.x && l.y === item.location.y; }), item); } }; StakingStrategy.prototype.removeItem = function (material, item) { this.delegate.removeItem(material.location(function (l) { return l.x === item.location.x && l.y === item.location.y; }), item); }; return StakingStrategy; }()); exports.StakingStrategy = StakingStrategy; //# sourceMappingURL=StakingStrategy.js.map