diff options
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/dice/ComplexDice.java')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/dice/ComplexDice.java | 70 |
1 files changed, 40 insertions, 30 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/dice/ComplexDice.java b/BJC-Utils2/src/main/java/bjc/utils/dice/ComplexDice.java index 98a510a..226f9fd 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/dice/ComplexDice.java +++ b/BJC-Utils2/src/main/java/bjc/utils/dice/ComplexDice.java @@ -9,6 +9,37 @@ package bjc.utils.dice; */ public class ComplexDice implements IDiceExpression { /** + * 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 ComplexDice fromString(String dice) { + /* + * Split it on the dice type marker + */ + String[] strangs = dice.split("d"); + + try { + /* + * Create the actual dice + */ + return new ComplexDice( + new ScalarDie(Integer.parseInt(strangs[0])), + new Die(Integer.parseInt(strangs[1]))); + } catch (NumberFormatException nfex) { + /* + * Tell the user the expression is invalid + */ + throw new IllegalArgumentException( + "Attempted to create a dice using something that's not" + + " an integer: " + strangs[0] + " and " + + strangs[1] + " are likely culprits."); + } + } + + /** * The die being rolled */ private IDiceExpression die; @@ -34,7 +65,7 @@ public class ComplexDice implements IDiceExpression { /** * Create a new collection of dice * - * @param nDce + * @param nSides * The number of dice in the collection * @param de * The type of dice the collection is composed of @@ -44,6 +75,11 @@ public class ComplexDice implements IDiceExpression { die = new Die(de); } + /* + * (non-Javadoc) + * + * @see bjc.utils.dice.IDiceExpression#roll() + */ @Override public int roll() { int res = 0; @@ -60,37 +96,11 @@ public class ComplexDice implements IDiceExpression { return res; } - /** - * Create a dice from a string expression + /* + * (non-Javadoc) * - * @param dice - * The string to parse the dice from - * @return A dice group parsed from the string + * @see java.lang.Object#toString() */ - public static ComplexDice fromString(String dice) { - /* - * Split it on the dice type marker - */ - String[] strangs = dice.split("d"); - - try { - /* - * Create the actual dice - */ - return new ComplexDice( - new ScalarDie(Integer.parseInt(strangs[0])), - new Die(Integer.parseInt(strangs[1]))); - } catch (NumberFormatException nfex) { - /* - * Tell the user the expression is invalid - */ - throw new IllegalArgumentException( - "Attempted to create a dice using something that's not" - + " an integer: " + strangs[0] + " and " - + strangs[1] + " are likely culprits."); - } - } - @Override public String toString() { if (nDice instanceof ScalarDie && die instanceof Die) { |
