summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/dice/CompoundDice.java
blob: 608174e61fd3f75d1b068e31cf3154fcf821b743 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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;
	}

	@Override
	public int roll() {
		/*
		 * Make the combination of the two dice
		 */
		return Integer.parseInt(l.roll() + "" + r.roll());
	}

	@Override
	public String toString() {
		return "compound[l=" + l.toString() + ", r=" + r.toString() + "]";
	}
}