9 private final Queue<Card> draw;
10 private final Stack<Card> discard;
11
12 public Deck() { 13 draw = new ArrayDeque<>(); 14 discard = new Stack<>(); 15 16 addCards(0, 9, Card.Color.RED); 17 addCards(1, 9, Card.Color.RED); 18 addCards(0, 9, Card.Color.BLUE); 19 addCards(1, 9, Card.Color.BLUE); 20 addCards(0, 9, Card.Color.GREEN); 21 addCards(1, 9, Card.Color.GREEN); 22 addCards(0, 9, Card.Color.YELLOW); 23 addCards(1, 9, Card.Color.YELLOW); 24 25 draw.add(new DrawTwoCard(Card.Color.RED)); 26 draw.add(new DrawTwoCard(Card.Color.RED)); 27 draw.add(new DrawTwoCard(Card.Color.BLUE)); 28 draw.add(new DrawTwoCard(Card.Color.BLUE)); 29 draw.add(new DrawTwoCard(Card.Color.YELLOW)); 30 draw.add(new DrawTwoCard(Card.Color.YELLOW)); 31 draw.add(new DrawTwoCard(Card.Color.GREEN)); 32 draw.add(new DrawTwoCard(Card.Color.GREEN)); 33 34 draw.add(new SkipCard(Card.Color.RED)); 35 draw.add(new SkipCard(Card.Color.RED)); 36 draw.add(new SkipCard(Card.Color.BLUE)); 37 draw.add(new SkipCard(Card.Color.BLUE)); 38 draw.add(new SkipCard(Card.Color.YELLOW)); 39 draw.add(new SkipCard(Card.Color.YELLOW)); 40 draw.add(new SkipCard(Card.Color.GREEN)); 41 draw.add(new SkipCard(Card.Color.GREEN)); 42 43 draw.add(new ReverseCard(Card.Color.RED)); 44 draw.add(new ReverseCard(Card.Color.RED)); 45 draw.add(new ReverseCard(Card.Color.BLUE)); 46 draw.add(new ReverseCard(Card.Color.BLUE)); 47 draw.add(new ReverseCard(Card.Color.YELLOW)); 48 draw.add(new ReverseCard(Card.Color.YELLOW)); 49 draw.add(new ReverseCard(Card.Color.GREEN)); 50 draw.add(new ReverseCard(Card.Color.GREEN)); 51 52 draw.add(new WildCard()); 53 draw.add(new WildCard()); 54 draw.add(new WildCard()); 55 draw.add(new WildCard()); 56 57 draw.add(new WildDrawFourCard()); 58 draw.add(new WildDrawFourCard()); 59 draw.add(new WildDrawFourCard()); 60 draw.add(new WildDrawFourCard()); 61 62 discard.addAll(draw); 63 draw.clear(); 64 65 shuffle(); 66 draw.add(discard.pop()); 67 68 } 69
70 private void addCards(int start, int end, Card.Color color) {
71 for (int i = start; i <= end; i++) {
5 protected int number;
6 protected Type type;
7
8 public Card(Color color, int number) { 9 this.color = color; 10 this.number = number; 11 this.type = Type.byName(number + ""); 12 } 13
14 protected Card(Color color, Type type) {
15 this.number = -1;
11 this.type = Type.byName(number + "");
12 }
13
14 protected Card(Color color, Type type) { 15 this.number = -1; 16 this.color = color; 17 this.type = type; 18 } 19
20 public static Card of(Type type, Color color) {
21 return switch (type) {
89 WILDE_DRAW_FOUR("WD4");
90 private final String name;
91
92 Type(String name) { 93 this.name = name; 94 } 95
96 public static Type byName(String name) {
97 for (Type value : values()) {
7 private final Player next;
8 private final Card.Color color;
9
10 public WildeEvent(Player next, Card.Color color) {11 super("Wild");12 this.next = next;13 this.color = color;14 }15
16 public Player getNext() {
17 return next;
This constructor does not have any documentation.
Consider adding a documentation comment to explain its use.
While it may seem like the usage of a constructor is perfectly obvious, any consumers of your API may not be able to pick up on certain details.
In the example below, it is difficult to understand what the arguments of this constructor for DataForwarder
signify.
class DataForwarder {
public DataForwarder(int nTypes, String... values) {
// ...
}
}
Document the constructor and provide useful information about it or its parameters as required.
/**
* Initializes a DataForwarder with a set of types to filter by, along with their names.
*
* @param nTypes - The number of types to filter by.
* @param values - The input type names to filter by.
*/
public DataForwarder(int nTypes, String... values) {
// ...
}
If you feel this constructor does not require documentation, you can add a skipcq comment to this constructor.