UNPKG

@gamepark/rules-api

Version:

API to implement the rules of a board game

40 lines 1.15 kB
import { MaterialRulesPart } from './MaterialRulesPart'; /** * Base class for any part of the rules where only one player has to do something. */ export class PlayerTurnRule extends MaterialRulesPart { /** * Shortcut to get the awaited player (this.game.rule.player) */ get player() { return this.game.rule.player; } /** * Utility function to get the id of the next player in the table order */ get nextPlayer() { return this.game.players[(this.game.players.indexOf(this.player) + 1) % this.game.players.length]; } /** * See {@link Rules.getActivePlayer} */ getActivePlayer() { return this.player; } /** * See {@link Rules.getLegalMoves} */ getLegalMoves(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 */ getPlayerMoves() { return []; } } //# sourceMappingURL=PlayerTurnRule.js.map