diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-02-21 15:40:30 -0500 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-02-21 15:40:30 -0500 |
| commit | 77a797089a2e065cc8cf2a83ae8356b16591aebe (patch) | |
| tree | e88f80b126cbb6de08881beb0a8c97111966a2b7 /BJC-Utils2/src/main/java/bjc/utils/dice/CompoundDiceExpression.java | |
| parent | d8b3b3c5e4441cecec98c06a36fc81570008c888 (diff) | |
Revamping of the way dice work
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/dice/CompoundDiceExpression.java')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/dice/CompoundDiceExpression.java | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/dice/CompoundDiceExpression.java b/BJC-Utils2/src/main/java/bjc/utils/dice/CompoundDiceExpression.java index c4ebbe5..4dd6926 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/dice/CompoundDiceExpression.java +++ b/BJC-Utils2/src/main/java/bjc/utils/dice/CompoundDiceExpression.java @@ -1,13 +1,39 @@ package bjc.utils.dice; -public class CompoundDiceExpression implements DiceExpression { +/** + * Implements a class for combining two dice with an operator + * + * @author ben + * + */ +public class CompoundDiceExpression implements IDiceExpression { + /** + * The operator to use for combining the dice + */ private DiceExpressionType det; - private DiceExpression left; - private DiceExpression right; + /** + * The dice on the left side of the expression + */ + private IDiceExpression left; - public CompoundDiceExpression(DiceExpression right, - DiceExpression left, DiceExpressionType det) { + /** + * The dice on the right side of the expression + */ + private IDiceExpression right; + + /** + * Create a new compound expression using the specified parameters + * + * @param right + * The die on the right side of the expression + * @param left + * The die on the left side of the expression + * @param det + * The operator to use for combining the dices + */ + public CompoundDiceExpression(IDiceExpression right, + IDiceExpression left, DiceExpressionType det) { this.right = right; this.left = left; this.det = det; @@ -15,6 +41,9 @@ public class CompoundDiceExpression implements DiceExpression { @Override public int roll() { + /* + * Handle each operator + */ switch (det) { case ADD: return right.roll() + left.roll(); @@ -23,11 +52,15 @@ public class CompoundDiceExpression implements DiceExpression { case MULTIPLY: return right.roll() * left.roll(); case DIVIDE: + /* + * Round to keep results as integers. + * We don't really have any need for floating-point dice + */ return Math.round(right.roll() / left.roll()); default: throw new IllegalStateException( "Got passed a invalid ScalarExpressionType " - + det); + + det + ". WAT"); } } |
