-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeck.java
More file actions
61 lines (37 loc) · 876 Bytes
/
Copy pathDeck.java
File metadata and controls
61 lines (37 loc) · 876 Bytes
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
/* Max Chwa
* Deck.java - A template for a Deck of Cards.
*/
public class Deck {
private Card[] cards;
private int top; // the index of the top of the deck
// add more instance variables if needed
public Deck(){
top = 0;
cards = new Card[52];
for (int i = 0; i < 52; i++) {
cards[i] = new Card(i%4 + 1, i/4 + 1);
}
}
public void shuffle(){
// shuffle the deck here
for (int i = 0; i < 50; i++) {
int placementOne = (int) (Math.random() * 52);
int placementTwo = (int) (Math.random() * 52);
Card temp = cards[placementOne];
cards[placementOne] = cards[placementTwo];
cards[placementTwo] = temp;
}
}
public Card deal(){
// deal the top card in the deck
top++;
if (top == 53) {
top = 1;
}
return cards[top - 1];
}
public int getTop() {
return top;
}
// add more methods here if needed
}