mirror of
https://github.com/dmuth/diceware.git
synced 2024-11-21 16:36:28 -05:00
Added convertBase6ToDice().
This commit is contained in:
parent
8aad4ea0ec
commit
acf5389ff7
1 changed files with 37 additions and 0 deletions
37
main.js
37
main.js
|
@ -85,6 +85,42 @@ Diceware.getBase6 = function(roll, num_dice) {
|
|||
} // End of getBase6()
|
||||
|
||||
|
||||
/**
|
||||
* Convert a base-6 number to a dice roll
|
||||
*
|
||||
* @param array roll An array of integers in base-6 notation
|
||||
* @param integer num_dice The number of dice rolled
|
||||
*
|
||||
* @return array An array of integers representing dice rolls
|
||||
*/
|
||||
Diceware.convertBase6ToDice = function(roll, num_dice) {
|
||||
|
||||
var retval = [];
|
||||
|
||||
if (roll.length != num_dice) {
|
||||
throw("Mismatch between size of roll (" + roll.length + ") and number of dice (" + num_dice + ")");
|
||||
}
|
||||
|
||||
for (var k in roll) {
|
||||
var num = roll[k];
|
||||
|
||||
if (num < 0) {
|
||||
throw("Value " + num + " is negative!");
|
||||
}
|
||||
|
||||
if (num > 5) {
|
||||
throw("Value " + num + " is too large!");
|
||||
}
|
||||
|
||||
num++;
|
||||
retval.push(num);
|
||||
}
|
||||
|
||||
return(retval);
|
||||
|
||||
} // End of convertBase6ToDice()
|
||||
|
||||
|
||||
/**
|
||||
* Roll a die.
|
||||
*
|
||||
|
@ -138,6 +174,7 @@ Diceware.roll_dice = function() {
|
|||
* @return string The word from the dicelist
|
||||
*/
|
||||
Diceware.get_word = function(wordlist, index) {
|
||||
|
||||
var retval = wordlist[index];
|
||||
|
||||
if (retval) {
|
||||
|
|
Loading…
Reference in a new issue