diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-03-18 19:47:49 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-03-18 19:50:05 -0400 |
| commit | 1bff7e49ed64d74e36d901e84c594cf63b58350b (patch) | |
| tree | 234ee635d36a5a4a26994e07ac2367f87b0cba3a /BJC-Utils2/src/main/java/bjc/utils/dice/LazyDice.java | |
| parent | 8ffe41a3575e7d9e4602deeb5f878c4687f4e389 (diff) | |
General changes to the dice package
The biggest change is the addition of variables and assignment
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/dice/LazyDice.java')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/dice/LazyDice.java | 93 |
1 files changed, 0 insertions, 93 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/dice/LazyDice.java b/BJC-Utils2/src/main/java/bjc/utils/dice/LazyDice.java deleted file mode 100644 index c1d775f..0000000 --- a/BJC-Utils2/src/main/java/bjc/utils/dice/LazyDice.java +++ /dev/null @@ -1,93 +0,0 @@ -package bjc.utils.dice; - -/** - * Implements a collection of one or more of a particular die, where the - * number of dice in the group is variable. - * - * @author ben - * - */ -public class LazyDice implements IDiceExpression { - /** - * The die being rolled - */ - private IDiceExpression die; - - /** - * The number of the specified die to roll - */ - private IDiceExpression nDice; - - /** - * Create a new collection of dice - * - * @param nDce - * The number of dice in the collection - * @param de - * The type of dice the collection is composed of - */ - public LazyDice(IDiceExpression nDce, IDiceExpression de) { - nDice = nDce; - die = de; - } - - /** - * Create a new collection of dice - * - * @param nDce - * The number of dice in the collection - * @param de - * The type of dice the collection is composed of - */ - public LazyDice(int nSides, int de) { - nDice = new ScalarDie(nSides); - die = new Die(de); - } - - @Override - public int roll() { - int res = 0; - - /* - * Add the results of rolling each die - */ - int nRoll = nDice.roll(); - - for (int i = 0; i < nRoll; i++) { - res += die.roll(); - } - - return res; - } - - /** - * Create a dice from a string expression - * - * @param dice - * The string to parse the dice from - * @return A dice group parsed from the string - */ - public static LazyDice fromString(String dice) { - /* - * Split it on the dice type marker - */ - String[] strangs = dice.split("d"); - - try { - /* - * Create the actual dice - */ - return new LazyDice( - new ScalarDie(Integer.parseInt(strangs[0])), - new Die(Integer.parseInt(strangs[1]))); - } catch (NumberFormatException nfex) { - /* - * Tell the user the expression is invalid - */ - throw new IllegalStateException( - "Attempted to create a dice using something that's not" - + " an integer: " + strangs[0] + " and " - + strangs[1] + " are likely culprits."); - } - } -} |
