-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathDeck.java
More file actions
84 lines (75 loc) · 2.01 KB
/
Deck.java
File metadata and controls
84 lines (75 loc) · 2.01 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import java.util.List;
import java.util.ArrayList;
/**
* Emulate a deck of cards
*
* @author Mr. Jaffe
* @version 2022-10-19
*/
public class Deck
{
private List<Card> cards;
/**
* Deck constructor: Create an empty deck of cards
*/
public Deck()
{
cards = new ArrayList<Card>();
}
public void initializeNewDeck() {
String[] suits = {"Hearts","Clubs","Spades","Diamonds"};
int[] ranks = {2,3,4,5,6,7,8,9,10,11,12,13,14};
String[] faces = {"2","3","4","5","6","7","8","9","10","Jack","Queen","King","Ace"};
for (String suit : suits) {
for (int idx=0; idx<ranks.length; idx++) {
Card c = new Card(ranks[idx], faces[idx], suit);
this.cards.add(c);
}
}
}
/**
* Get the number of cards in the deck
*
* @returns Number of cards in the deck
*/
public int getDeckSize() {
return cards.size();
}
/**
* Shuffles the cards in the deck
*/
public void shuffle() {
// To be written
}
/**
* Deal all the cards in the deck to make two new decks of cards
*
* @returns Deck array where index 0 is the first deck and index 1 is the second deck
*/
public Deck[] dealDeck() {
Deck[] halves = new Deck[2];
halves[0] = new Deck();
halves[1] = new Deck();
boolean idx = false;
while (this.cards.size() > 0) {
halves[idx ? 0 : 1].addCardToDeck(this.dealCardFromDeck());
idx = !idx;
}
return halves;
}
/**
* Deal the top card of the deck and remove it from the deck
* @returns The top card of the deck (at cards index 0)
*/
public Card dealCardFromDeck() {
// To be written
return null;
}
/**
* Adds the provided card to the deck
* @param cardToAdd: Card to add to this deck
*/
public void addCardToDeck(Card cardToAdd) {
// To be written
}
}