-
Notifications
You must be signed in to change notification settings - Fork 0
/
Deck.java
53 lines (48 loc) · 1.27 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
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
import java.io.*;
import javax.imageio.*;
import java.util.*;
//models a deck of 52 standard playing cards, each with 21 Blackjack values
//Ace = 11 by default, 1 in the case of a bust
//Jack, Queen, King = 10
//All other cards have value shown
public class Deck{
private ArrayList<Card> cards;
//fills the deck of cards with 21 Blackjack values
public Deck(){
cards = new ArrayList<Card>();
for (int y = 0; y < 4; y++){
for (int x = 0; x < 13; x++){
int value;
if (x == 0){
value = 11;
}
else if (x >= 10)
{
value = 10;
}
else{
value = x + 1;
}
cards.add(new Card(value, x * 72, y * 96));
}
}
shuffle();
}
//shuffles the deck
public void shuffle(){
Collections.shuffle(cards);
}
//removes the top card from the deck and passes it to a hand
public void passCardTo(Hand recipient){
recipient.takeCard(cards.remove(0));
}
//receives a card from a hand
public void getCardsFrom(Hand source){
while(source.hasCards()){
cards.add(source.returnCard());
}
}
}