-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeck.java
executable file
·56 lines (45 loc) · 1 KB
/
Deck.java
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
import java.util.Arrays;
public class Deck
{
public static final int NUMFACES = 13;
public static final int NUMSUITS = 4;
public static final int NUMCARDS = 52;
public int topCardIndex = 0;
public Card[] stack;
//instance variables
public Card[] cards;
//constructor
public Deck()
{
cards = new Card[52];
int i = 0;
for(int s = 0;s < 4;s++)
{
for(int v = 1;v <= 13; v++)
{
cards[i] = new Card(s,v);
i++;
}
}
shuffle();
}
public void shuffle()
{
//mix up cards
for(int i=0;i < 52;i++)
{
int rand1 = (int)(Math.random() * cards.length);
int rand2 = (int)(Math.random() * cards.length);
Card tmp = cards[rand1];
cards[rand1] = cards[rand2];
cards[rand2] = tmp;
}
}
public String toString() {
String out = "";
for (int i = 0; i < cards.length; i++) {
out = out + cards[i] + "\n";
}
return out;
}
}