Here is a little class to roll dice given a string in standard dice notation, e.g. 2d20+3
.
Instantiate an instance of the class for each player, and then go nuts!
// instantiate yo' players
const playerSarah = new diceRoller();
const playerEli = new diceRoller();
// play the game
playerSarah.roll('2d10-4');
playerEli.roll('2d12+12');
playerSarah.roll('1d12');
playerEli.roll('1d2');
// check the log!
console.log('==== Sarah\'s log ====');
playerSarah.log.forEach(logEntry => {
console.log(logEntry.input + " : " + logEntry.result + " : " + logEntry.timestamp);
});
console.log('==== Eli\'s log ====');
playerEli.log.forEach(logEntry => {
console.log(logEntry.input + " : " + logEntry.result + " : " + logEntry.timestamp);
});