From 78d9c539e25f16fd15f06c2b2c48c0ad37a21540 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Mon, 28 Mar 2016 08:44:54 -0400 Subject: Imported dice stuff from general utils into dedicated project --- dice-lang/src/bjc/utils/dice/CompoundDice.java | 80 ++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 dice-lang/src/bjc/utils/dice/CompoundDice.java (limited to 'dice-lang/src/bjc/utils/dice/CompoundDice.java') diff --git a/dice-lang/src/bjc/utils/dice/CompoundDice.java b/dice-lang/src/bjc/utils/dice/CompoundDice.java new file mode 100644 index 0000000..3393711 --- /dev/null +++ b/dice-lang/src/bjc/utils/dice/CompoundDice.java @@ -0,0 +1,80 @@ +package bjc.utils.dice; + +/** + * Implements a "compound dice" + * + * To explain, a compound dice is something like a d100 composed from two + * d10s instead of a hundred sided die. + * + * @author ben + * + */ +public class CompoundDice implements IDiceExpression { + /** + * The left die of the expression + */ + private IDiceExpression l; + + /** + * The right die of the expression + */ + private IDiceExpression r; + + /** + * Create a new compound dice using the specified dice + * + * @param l + * The die to use on the left + * @param r + * The die to use on the right + */ + public CompoundDice(IDiceExpression l, IDiceExpression r) { + this.l = l; + this.r = r; + } + + /** + * Create a new compound dice from two dice strings + * + * @param l + * The left side dice + * @param r + * The right side dice + */ + public CompoundDice(String l, String r) { + this(ComplexDice.fromString(l), ComplexDice.fromString(r)); + } + + /** + * Create a new compound dice from an array of dice strings + * + * @param exps + * An array of dice strings + */ + public CompoundDice(String[] exps) { + this(exps[0], exps[1]); + } + + /* + * (non-Javadoc) + * + * @see bjc.utils.dice.IDiceExpression#roll() + */ + @Override + public int roll() { + /* + * Make the combination of the two dice + */ + return Integer.parseInt(l.roll() + "" + r.roll()); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "compound[l=" + l.toString() + ", r=" + r.toString() + "]"; + } +} -- cgit v1.2.3