-
Notifications
You must be signed in to change notification settings - Fork 1
/
DicesList.java
63 lines (54 loc) · 1.38 KB
/
DicesList.java
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
import greenfoot.*;
/**
Erstellt eine gegebene Anzahl an Dices's, welche dann nebeneinander eingereiht werden.
@author Felix Stupp
@version 15.06.2016
*/
public abstract class DicesList extends Actor {
private final static int SQUARESIZE = 100; // Anpassbar
private Dice[] dices;
public DicesList(int count, int max, java.awt.Color bC, java.awt.Color fC) {
setImage(new GreenfootImage(2,2));
if(count < 1) {
count = 1;
} else if (count > max) {
count = max;
}
for(int i = 1; i < count; i++) {
Dice d = new Dice();
d.setBackColor(bC);
d.setForeColor(fC);
d.setSizeAsSquare(SQUARESIZE);
dices[i] = d;
}
}
protected void addedToWorld(World w) {
for(int i = 0; i < dices.length; i++) {
w.addObject(dices[i],getX()+(SQUARESIZE*(6/5)*i),getY());
}
//w.removeObject(this); // Zeile auskommentieren, wenn die Debug-Phase vorbei ist.
}
public int[] getNumbers() {
int[] n = new int[dices.length];
for(int i = 0; i < dices.length; i++) {
n[i] = dices[i].getNumber();
}
Utils.sortDesc(n);
return n;
}
public int[] roll() {
int[] n = new int[dices.length];
for(int i = 0; i < dices.length; i++) {
n[i] = dices[i].roll();
}
Utils.sortDesc(n);
return n;
}
public void removeAll() {
for(int i = 0; i < dices.length; i++) {
dices[i].getWorld().removeObject(dices[i]);
}
getWorld().removeObject(this);
dices = new Dice[0];
}
}