-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiceBag.java
More file actions
91 lines (82 loc) · 2.06 KB
/
Copy pathDiceBag.java
File metadata and controls
91 lines (82 loc) · 2.06 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import java.util.ArrayList;
import java.util.Collections;
/**
* DiceBag - Contains die objects and rolls them. Should be able to save a
* profile to file so the user can save and use different setups.
*
* @author Even A. Nilsen
* @version v0.1 05.05.2015
*/
public class DiceBag
{
private ArrayList<Die> dice;
private String label;
/**
* Default constructor
* @param label used to identify the dice bag
*/
public DiceBag(String label) {
this.label = label;
dice = new ArrayList<Die>();
addDefaultDice();
}
/**
* Creates and adds one of each of the 7 dice
*/
protected void addDefaultDice() {
dice.add(new Die(4));
dice.add(new Die(6));
dice.add(new Die(8));
dice.add(new Die(10));
dice.add(new Die(12));
dice.add(new Die(20));
dice.add(new Die(100));
}
/**
* Prints the contents of the dice bag
*/
public void printDice() {
Collections.sort(dice, Die.sorter);
for(Die d : dice) {
System.out.println(d.getLabel());
}
}
/**
* Lets the user add dice
* @param nSides number of sides on the die
*/
public void addDie(int nSides) {
dice.add(new Die(nSides));
}
/**
* Returns the dica bags label
* @return label
*/
public String getLabel() {
return label;
}
/**
* Finds a die object and returns it. Returns null if not found.
* @param label what to search for
* @return d
*/
protected Die findDie(String label) {
for(Die d : dice) {
if(label.equals(d.getLabel()))
return d;
}
return null;
}
/**
* Search and remove all occurences with the chosen label
* @param label what to search for
*/
public void removeDie(String label) {
ArrayList<Die> rList = new ArrayList<Die>();
for(Die d : dice) {
if(label.equals(d.getLabel()))
rList.add(d);
}
dice.removeAll(rList);
}
}