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
No related branches found
No related tags found
1 merge request!3Added HandOfCard class to
...@@ -24,20 +24,20 @@ public class DeckOfCards { ...@@ -24,20 +24,20 @@ public class DeckOfCards {
return deck; return deck;
} }
public Collection<PlayingCard> dealHand(int n) { public HandOfCards dealHand(int n) {
if (n < 0 || n > deck.size()) { if (n < 0 || n > deck.size()) {
throw new IllegalArgumentException("Invalid number of cards to deal"); 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++) { for (int i = 0; i < n; i++) {
int cardIndex = random.nextInt(deck.size()); int cardIndex = random.nextInt(deck.size());
if (hand.contains(deck.get(cardIndex))) { if (hand.getHand().contains(deck.get(cardIndex))) {
i--; i--;
} else { } else {
hand.add(deck.remove(cardIndex)); hand.addCard(deck.get(cardIndex));
} }
} }
return hand; return hand;
} }
@Override @Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment