-
Notifications
You must be signed in to change notification settings - Fork 0
/
Deck.java
69 lines (59 loc) · 1.35 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
57
58
59
60
61
62
63
64
65
66
67
68
69
package pokerhands;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import pokerhands.Card.SUIT;
/**
*
* @author jfritz
*/
public class Deck
{
ArrayList<Card> cards = new ArrayList<>();
private int index = 0;
public Deck()
{
for (SUIT s : Card.SUIT.values())
{
for (int r = 1; r < 14; r++)
{
cards.add(new Card(r, s));
}
}
}
public void shuffle()
{
Random generator = new Random();
for (int i = 0; i < 1000; i++)
{
int index1 = generator.nextInt(52);
cards.add(cards.remove(index1));
}
this.index = 0;
}
public Card drawCard()
{
this.index++;
return cards.get(index - 1);
}
public List<Card> drawCards(int howMany)
{
ArrayList<Card> drawnCards = new ArrayList<>();
for(int i = 0; i < howMany; i++)
{
drawnCards.add(this.drawCard());
}
return drawnCards;
}
@Override
public String toString()
{
StringBuilder sb = new StringBuilder();
for (Card c : cards)
{
sb.append(c.toString());
sb.append(System.getProperty("line.separator"));
}
return sb.toString();
}
}