From 9139064c95f6c9c4f7ba1d0aea21e2f5233ad188 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Mon, 6 Mar 2017 14:15:03 -0500 Subject: Formatting/Documentation --- .../src/bjc/dicelang/dice/CompoundingDie.java | 31 +++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'dice-lang/src/bjc/dicelang/dice/CompoundingDie.java') diff --git a/dice-lang/src/bjc/dicelang/dice/CompoundingDie.java b/dice-lang/src/bjc/dicelang/dice/CompoundingDie.java index 9744650..3291b52 100644 --- a/dice-lang/src/bjc/dicelang/dice/CompoundingDie.java +++ b/dice-lang/src/bjc/dicelang/dice/CompoundingDie.java @@ -2,16 +2,37 @@ package bjc.dicelang.dice; import java.util.function.Predicate; +/** + * Implements a compounding die. + * + * This means that the source will be rolled, and then more single rolls will be + * added while it meets a qualification. + * + * @author Ben Culkin + */ public class CompoundingDie implements Die { private Die source; private Predicate compoundOn; private String compoundPattern; + /** + * Create a new compounding die with no pattern. + * + * @param src The die to compound from + * @param compound The conditions to compound on + */ public CompoundingDie(Die src, Predicate compound) { this(src, compound, null); } + /** + * Create a new compounding die with a specified pattern. + * + * @param src The die to compound from + * @param compound The conditions to compound on + * @param patt The string pattern the condition came from, for printing + */ public CompoundingDie(Die src, Predicate compound, String patt) { source = src; @@ -19,14 +40,17 @@ public class CompoundingDie implements Die { compoundPattern = patt; } + @Override public boolean canOptimize() { return source.canOptimize() && source.optimize() == 0; } + @Override public long optimize() { return 0; } + @Override public long roll() { long res = source.roll(); long oldRes = res; @@ -40,7 +64,11 @@ public class CompoundingDie implements Die { return res; } + @Override public long rollSingle() { + /* + * Just compound on a single roll + */ long res = source.rollSingle(); long oldRes = res; @@ -53,6 +81,7 @@ public class CompoundingDie implements Die { return res; } + @Override public String toString() { if(compoundPattern == null) { return source + "!!"; @@ -60,4 +89,4 @@ public class CompoundingDie implements Die { return source + "!!" + compoundPattern; } } -} \ No newline at end of file +} -- cgit v1.2.3