playship_ludo_pseudo_quick
Version:
Server side neutrino plugin code for ludo game
29 lines (26 loc) • 776 B
JavaScript
function ShuffleRoller(meta, dieRollShuffledBagGenerator) {
this._maxRoll = meta.rollDieMax || 6;
this._bagMultiplier = meta.bagMultiplier || 2;
this._noOfBags = meta.totalDiceBags || 5;
this.bag = [];
this.index = 0;
this.dieRollShuffledBagGenerator = dieRollShuffledBagGenerator;
resetBag.call(this);
}
ShuffleRoller.prototype.nextRoll = function() {
if (this.index === this.bag.length)
resetBag.call(this);
return this.bag[this.index++];
};
function resetBag() {
this.index = 0;
this.bag = []
for(let i = 0 ; i < this._noOfBags; i++){
let bag = this.dieRollShuffledBagGenerator(this._maxRoll,
this._bagMultiplier);
for(let j = 0 ; j < bag.length ; j++){
this.bag.push(bag[j]);
}
}
}
module.exports = ShuffleRoller;