-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeck.java
More file actions
49 lines (42 loc) · 1.31 KB
/
Deck.java
File metadata and controls
49 lines (42 loc) · 1.31 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
import java.util.ArrayList;
import java.util.Collections;
public class Deck {
// Deck wil need cards obviously
ArrayList<Card> cards;
public int getDeckSize() {
// Returns the current number of cards left in the deck
return cards.size();
}
public void shuffleDeck() {
// Uses the Collections.shuffle method to shuffle up the deck and get the cards
// in randomized order
Collections.shuffle(cards);
}
public Card drawCard() {
// Draws a card from the deck and then removes it from the cards in the deck.
Card drawn = cards.get(0);
cards.remove(0);
return drawn;
}
// Deck constructor
public Deck() {
// Create 52 cards for the deck and shuffle them
cards = new ArrayList<Card>();
String suit = "";
for (int i = 0; i < 4; ++i) {
if (i == 0) {
suit = "hearts";
} else if (i == 1) {
suit = "clubs";
} else if (i == 2) {
suit = "spades";
} else if (i == 3) {
suit = "diamonds";
}
for (int j = 2; j <= 14; ++j) {
cards.add(new Card(suit, j));
}
}
shuffleDeck();
}
}