-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDraw_Pile.java
More file actions
35 lines (29 loc) · 1013 Bytes
/
Draw_Pile.java
File metadata and controls
35 lines (29 loc) · 1013 Bytes
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
import java.util.Collections;
import java.util.*;
public class Draw_Pile {
private ArrayList <Card> deck;
private int topCardIndex;
public Draw_Pile() { //constructor
deck = new ArrayList<Card>();
this.topCardIndex = 51;
// GENERATE PERMUTATIONS
for (Card.Suit s : Card.Suit.values()) { // loop through suits
for (Card.Rank r : Card.Rank.values()) { // loop through ranks
deck.add(new Card(s, r)); //add a new card to the deck
}//end rank loop
} // end suit loop
Collections.shuffle(deck);
}// end Draw_Pile CONSTRUCTOR
public int getTopCardIndex() {
return topCardIndex;
}
public void setTopCardIndex(int topCardIndex) {
this.topCardIndex = topCardIndex;
}
public Card drawCard(Draw_Pile deck){ //function to return a card and remove it from the deck
Card drawnCard = this.deck.get(getTopCardIndex());
this.deck.remove(this.topCardIndex);
this.setTopCardIndex(this.getTopCardIndex() - 1);
return drawnCard;
}//end drawCard() function
}//end Draw_Pile class