-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDeck.java
48 lines (44 loc) · 1.16 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
package jl223vy_assign3;
import java.util.*;
import jl223vy_assign3.Card.Ranks;
import jl223vy_assign3.Card.Suits;
public class Deck {
private ArrayList<Card> deck=new ArrayList<Card>();
private int cardsUsed=0;
private int cardsLeft=52;
public Deck(){
for (Suits suit: Suits.values()){
for (Ranks rank: Ranks.values()){
deck.add(new Card(rank,suit));
}
}
}
public void shuffle(){
if(cardsLeft!=52)
throw new IllegalStateException("shuffle cannot be used without 52 cards");
else{
Collections.shuffle(deck);
cardsUsed=0;
cardsLeft=52;
}
}
public void putAllCardsBackToDeck(){
cardsUsed=0;
cardsLeft=52;
}
public int cardsLeft(){ return cardsLeft; }
public void dealCard(){
if (cardsLeft<0)
throw new IllegalStateException("No cards are left in the deck.");
cardsUsed++;
cardsLeft--;
}
public int dealtCardRank(){
return deck.get(cardsUsed-1).getRank().ordinal();
}
public void dealtCards(){
for(int i=0; i<cardsUsed; i++){
System.out.println(deck.get(i).toString());
}
}
}