38 lines
839 B
Java
38 lines
839 B
Java
![]() |
package jrummikub.model;
|
||
|
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.EnumSet;
|
||
|
import java.util.List;
|
||
|
import java.util.Random;
|
||
|
|
||
|
public class StoneHeap {
|
||
|
List<Stone> heap;
|
||
|
Random generator = new Random();
|
||
|
|
||
|
public StoneHeap() {
|
||
|
heap = new ArrayList<Stone>();
|
||
|
for (int i = 1; i <= 13; i++) {
|
||
|
for (int j = 0; j < 2; j++) {
|
||
|
for (StoneColor c : EnumSet.allOf(StoneColor.class)) {
|
||
|
heap.add(new Stone(i, c, false));
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
// Joker
|
||
|
heap.add(new Stone(0, StoneColor.BLACK, true));
|
||
|
heap.add(new Stone(0, StoneColor.ORANGE, true));
|
||
|
}
|
||
|
|
||
|
public Stone drawStone() {
|
||
|
return heap.remove(generator.nextInt(heap.size()));
|
||
|
}
|
||
|
|
||
|
public List<Stone> drawStones(int number) {
|
||
|
List<Stone> drawnStones = new ArrayList<Stone>();
|
||
|
for (int i=0; i<number; i++){
|
||
|
drawnStones.add(drawStone());
|
||
|
}
|
||
|
return drawnStones;
|
||
|
}
|
||
|
}
|