From 77a797089a2e065cc8cf2a83ae8356b16591aebe Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Sun, 21 Feb 2016 15:40:30 -0500 Subject: Revamping of the way dice work --- .../bjc/utils/dice/CompoundDiceExpression.java | 45 +++++++++++++++++++--- 1 file changed, 39 insertions(+), 6 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/dice/CompoundDiceExpression.java') 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"); } } -- cgit v1.2.3