UNPKG

@andreabiagini5/applicazioni-e-servizi-web-project

Version:
45 lines 1.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CellFactory = void 0; const Pile_1 = require("./Pile"); class CellFactory { } exports.CellFactory = CellFactory; /** * Cell factory. Returns a cell with the provided pile inside it. * @param pile the pile to be put inside the cell * @returns a cell with the provided pile inside */ CellFactory.create = (pile) => new CellImpl(pile); /** * Cell factory. Returns a cell with no pile inside it. * @returns a cell with no pile inside */ CellFactory.createEmpty = () => CellFactory.create(null); class CellImpl { constructor(pile) { this.pile = pile; } addGrain(player) { if (this.pile == null) { // If the pile does not exist, it creates it this.pile = Pile_1.PileFactory.create(player, 1); } else { // Else, the number of grains is incremented this.pile.numberOfGrains++; this.pile.owner = player; } } collapse() { if (this.pile != null) { if (this.pile.numberOfGrains > 4) { this.pile.numberOfGrains = this.pile.numberOfGrains - 4; } else if (this.pile.numberOfGrains == 4) { this.pile = null; } } } } //# sourceMappingURL=Cell.js.map