diff options
Diffstat (limited to 'dice/src/main/java/bjc/dicelang/neodice/diepool/TimesDiePool.java')
| -rw-r--r-- | dice/src/main/java/bjc/dicelang/neodice/diepool/TimesDiePool.java | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/dice/src/main/java/bjc/dicelang/neodice/diepool/TimesDiePool.java b/dice/src/main/java/bjc/dicelang/neodice/diepool/TimesDiePool.java new file mode 100644 index 0000000..1b34247 --- /dev/null +++ b/dice/src/main/java/bjc/dicelang/neodice/diepool/TimesDiePool.java @@ -0,0 +1,58 @@ +package bjc.dicelang.neodice.diepool; + +import java.util.*; + +import bjc.dicelang.neodice.*; + +public class TimesDiePool implements DiePool { + private final Die contained; + private final int numDice; + + public TimesDiePool(Die contained, int numDice) { + this.contained = contained; + this.numDice = numDice; + } + + @Override + public int[] roll(Random rng) { + int[] results = new int[numDice]; + + for (int index = 0; index < numDice; index++) { + results[index] = contained.roll(rng); + } + + return results; + } + + @Override + public Die[] contained() { + Die[] results = new Die[numDice]; + + for (int index = 0; index < numDice; index++) { + results[index] = contained; + } + + return results; + } + + @Override + public String toString() { + return String.format("%d%s", numDice, contained); + } + + @Override + public int hashCode() { + return Objects.hash(contained, numDice); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (getClass() != obj.getClass()) return false; + + TimesDiePool other = (TimesDiePool) obj; + + return Objects.equals(contained, other.contained) && numDice == other.numDice; + } +}
\ No newline at end of file |
