Skip to content
Snippets Groups Projects
Commit ded8afc0 authored by Scott Langum Du Plessis's avatar Scott Langum Du Plessis
Browse files

Added HandOfCard class to

follow good practises
parent 93eefc38
Branches
No related tags found
1 merge request!3Added HandOfCard class to
......@@ -24,17 +24,17 @@ public class DeckOfCards {
return deck;
}
public Collection<PlayingCard> dealHand(int n) {
public HandOfCards dealHand(int n) {
if (n < 0 || n > deck.size()) {
throw new IllegalArgumentException("Invalid number of cards to deal");
}
Collection<PlayingCard> hand = new ArrayList<>();
HandOfCards hand = new HandOfCards();
for (int i = 0; i < n; i++) {
int cardIndex = random.nextInt(deck.size());
if (hand.contains(deck.get(cardIndex))) {
if (hand.getHand().contains(deck.get(cardIndex))) {
i--;
} else {
hand.add(deck.remove(cardIndex));
hand.addCard(deck.get(cardIndex));
}
}
return hand;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment