This is the Deck.java code for video poker game
Fri Dec 13 2024 06:17:06 GMT+0000 (Coordinated Universal Time)
Saved by
@Sasere
// Banner: Deck class for managing a standard 52-card deck.
public class Deck {
private Card[] cards;
private int top; // Tracks the top of the deck
public Deck() {
cards = new Card[52];
int index = 0;
for (int suit = 1; suit <= 4; suit++) {
for (int rank = 1; rank <= 13; rank++) {
cards[index++] = new Card(suit, rank);
}
}
top = 0;
}
public void shuffle() {
List<Card> cardList = Arrays.asList(cards);
Collections.shuffle(cardList);
cards = cardList.toArray(new Card[0]);
}
public Card deal() {
if (top < cards.length) {
return cards[top++];
}
throw new IllegalStateException("No cards left in the deck!");
}
public void resetDeck() {
top = 0;
shuffle();
}
}
content_copyCOPY
Comments