Skip to content
Snippets Groups Projects

Fix filpath in PlayingCard and implement code in DeckOfCards

Merged Edvard Berdal Eek requested to merge feat/model into dev
2 files
+ 31
2
Compare changes
  • Side-by-side
  • Inline
Files
2
package no.ntnu.idatt2002.a4.cardgame.model;
import java.util.HashMap;
import java.util.*;
public class DeckOfCards {
private HashMap<Integer, PlayingCard> deck;
private final char[] suits = {'H', 'D', 'S', 'C'};
public DeckOfCards() {
deck = new HashMap<>();
int iteration = 0;
for (char suit : suits) {
for (int i = 1; i < 14; i++) {
iteration++;
deck.put(iteration, new PlayingCard(suit, i));
}
}
}
public HashMap<Integer, PlayingCard> getDeck() {
return deck;
}
public List<PlayingCard> dealHand(int numberOfCards) {
Random random = new Random();
List<PlayingCard> hand = new ArrayList<>(numberOfCards);
HashSet<Integer> dealtKeys = new HashSet<>();
for (int i = 0; i < numberOfCards; i++) {
int randomKey = random.nextInt( this.deck.size());
while (dealtKeys.contains(randomKey)) {
randomKey = random.nextInt(this.deck.size());
}
hand.add(deck.get(randomKey));
dealtKeys.add(randomKey);
}
return hand;
}
}
Loading