-
Notifications
You must be signed in to change notification settings - Fork 0
/
Deck.java
81 lines (63 loc) · 1.53 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
70
71
72
73
74
75
76
77
78
79
80
81
import java.util.Random;
/**
* @author nicolasnoriega
* @descrition Simulates a game of BlackJack between a single player and a dealer following the standard rules
* @datedue February 13th, 2020
*/
public class Deck
{
private Card[] deck;
private int numOfCardsPerDeck = 52;
private int topCardIndex = 0;
private int nextCardToBeDealt;
public Deck()
{
Card.Ranks[] Rank = {
Card.Ranks.Ace,
Card.Ranks.Two,
Card.Ranks.Three,
Card.Ranks.Four,
Card.Ranks.Five,
Card.Ranks.Six,
Card.Ranks.Seven,
Card.Ranks.Eight,
Card.Ranks.Nine,
Card.Ranks.Ten, Card.Ranks.Jack, Card.Ranks.Queen, Card.Ranks.King
};
Card.Suits[] Suit = {
Card.Suits.Clubs,
Card.Suits.Spades,
Card.Suits.Diamonds,
Card.Suits.Hearts
};
deck = new Card[numOfCardsPerDeck];
nextCardToBeDealt = 0;
for(int i = 0; i < deck.length; i++)
{
deck[i] = new Card(Suit [i / 13], Rank[i % 13]);
}
}
public void shuffleCards()
{
nextCardToBeDealt = 0;
for(int i = 0; i < deck.length; i++)
{
Random random = new Random();
int cardToBeSwappedWith = random.nextInt(numOfCardsPerDeck);
Card temp = deck[i];
deck[i] = deck[cardToBeSwappedWith];
deck[cardToBeSwappedWith] = temp;
}
}
public Card dealTopCard()
{
Card topCards = this.deck[0]; //Grabs the first card
for(int i = 1; i < numOfCardsPerDeck; i++)
{
this.deck[i - 1] = this.deck[i];
}
this.deck[numOfCardsPerDeck - 1] = null;
numOfCardsPerDeck--;
return topCards;
}
}