|
class Cards implements BelotConstants { Cards() { currentPosition = 0; deck = new Card[CARDS_IN_DECK]; int cardNumber = 0; int cardIndex = 0; for (int s = CLUBS; s <= SPADES; s++) { for (int r = EIGHT; r <= ACE; r++) { deck[cardNumber] = new Card (s, r, VALUES[r], cardIndex); cardIndex++; cardNumber++; } cardIndex = cardIndex + 3; // skip when suit changes } } public void assignValues(int trump) { for (int i = 0; i < deck.length; i++) deck[i].updateValue(trump); } public Card getNextCard () { Card temp = deck[currentPosition]; currentPosition++; return temp; } public Card showNextCard () { return deck[currentPosition]; } public void shuffle() { Card card; int swapPosition; currentPosition = 0; // interface for (int i = 0; i < deck.length; i++) { swapPosition = (int) (Math.random() * deck.length); card = deck[i]; deck[i] = deck[swapPosition]; deck[swapPosition] = card; } } public Card getCard (int position) // interface { return deck[position]; } private Card [] deck; private int currentPosition; } |