-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeck.java
More file actions
54 lines (45 loc) · 1.27 KB
/
Copy pathDeck.java
File metadata and controls
54 lines (45 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.util.Random;
public class Deck {
private static final int DECK_SIZE = 52;
private static final int SHUFFLE_EXCHANGES = 2000;
private static final int HAND_SIZE = 5;
private Card[] deck = new Card[DECK_SIZE];
private int restOfDeck = 6;
private Random random;
public Deck() {
random = new Random();
}
public void fillDeck() {
int counter = 0;
for (int suit = 1; suit <= 4; suit++) {
for (int rank = 1; rank <= 13; rank++) {
Card card = new Card();
card.setSuit(suit);
card.setRank(rank);
deck[counter] = card;
counter++;
}
}
}
public void shuffle() {
for (int i = DECK_SIZE - 1; i >= 1; i--) {
int j = random.nextInt(i + 1);
Card temp = deck[i];
deck[i] = deck[j];
deck[j] = temp;
}
}
public Card[] deal() {
Card[] hand = new Card[HAND_SIZE];
System.arraycopy(deck, 0, hand, 0, HAND_SIZE);
return hand;
}
public Card drawNext() {
Card nextCard = deck[restOfDeck];
restOfDeck++;
return nextCard;
}
public void refreshDeckPosition() {
restOfDeck = 6;
}
}