Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.Random;
- public class Deck {
- private static Random rnd = new Random();
- Card[] cards;
- int start;
- public Deck() {
- int cardsCount = Card.CARD_TYPE.length() * Card.CARD_VALUE.length;
- cards = new Card[cardsCount];
- for (int t = 0; t < Card.CARD_TYPE.length(); t++) {
- char type = Card.CARD_TYPE.charAt(t);
- for (int v = 0; v < Card.CARD_VALUE.length; v++) {
- cards[v + 13 * t] = new Card(type, v + 1);
- }
- }
- for (int i = 0; i < cardsCount; i++) {
- int c1, c2;
- c1 = rnd.nextInt(cardsCount);
- do {
- c2 = rnd.nextInt(cardsCount);
- } while (c1 == c2);
- Card temp = cards[c1];
- cards[c1] = cards[c2];
- cards[c2] = temp;
- }
- start = 0;
- }
- public Card[] getCards(int count) {
- int last = start + count;
- Card[] res = Arrays.copyOfRange(cards, start, last);
- start = last;
- return res;
- }
- public int getCount() {
- return cards.length - start;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement