@gamepark/rules-api
Version:
API to implement the rules of a board game
25 lines • 1.35 kB
JavaScript
import { PositiveSequenceStrategy } from './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.
*/
export class StackingStrategy {
delegate = new PositiveSequenceStrategy('z');
addItem(material, item) {
this.delegate.addItem(material.location(l => l.x === item.location.x && l.y === item.location.y), item);
}
moveItem(material, item, index) {
const itemBefore = material.getItem(index);
if (itemBefore.location.x === item.location.x && itemBefore.location.y === item.location.y) {
this.delegate.moveItem(material.location(l => l.x === item.location.x && l.y === item.location.y), item, index);
}
else {
this.delegate.removeItem(material.index(i => i !== index).location(l => l.x === itemBefore.location.x && l.y === itemBefore.location.y), itemBefore);
this.delegate.addItem(material.location(l => l.x === item.location.x && l.y === item.location.y), item);
}
}
removeItem(material, item) {
this.delegate.removeItem(material.location(l => l.x === item.location.x && l.y === item.location.y), item);
}
}
//# sourceMappingURL=StackingStrategy.js.map