UNPKG

@gamepark/rules-api

Version:

API to implement the rules of a board game

72 lines 2.71 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.PlayerTurnRule = void 0; var MaterialRulesPart_1 = require("./MaterialRulesPart"); /** * Base class for any part of the rules where only one player has to do something. */ var PlayerTurnRule = /** @class */ (function (_super) { __extends(PlayerTurnRule, _super); function PlayerTurnRule() { return _super !== null && _super.apply(this, arguments) || this; } Object.defineProperty(PlayerTurnRule.prototype, "player", { /** * Shortcut to get the awaited player (this.game.rule.player) */ get: function () { return this.game.rule.player; }, enumerable: false, configurable: true }); Object.defineProperty(PlayerTurnRule.prototype, "nextPlayer", { /** * Utility function to get the id of the next player in the table order */ get: function () { return this.game.players[(this.game.players.indexOf(this.player) + 1) % this.game.players.length]; }, enumerable: false, configurable: true }); /** * See {@link Rules.getActivePlayer} */ PlayerTurnRule.prototype.getActivePlayer = function () { return this.player; }; /** * See {@link Rules.getLegalMoves} */ PlayerTurnRule.prototype.getLegalMoves = function (player) { if (player !== this.getActivePlayer()) return []; return this.getPlayerMoves(); }; /** * Implement this to expose all the legal moves of the active player. * @returns All the {@link MaterialMove} that current active player can play */ PlayerTurnRule.prototype.getPlayerMoves = function () { return []; }; return PlayerTurnRule; }(MaterialRulesPart_1.MaterialRulesPart)); exports.PlayerTurnRule = PlayerTurnRule; //# sourceMappingURL=PlayerTurnRule.js.map