3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by JamesCherrill
0

Depends on how you define/store a Deck.
Ideally Deck will be a class, so you can just have an array of them:

Deck[] myDecks = new Deck[8];  // create array
for (int 1 = 0; i < myDecks.length; i++) {
   myDecks[i] = new Deck(...); // initialise array
}

but if your deck is just a crummy array of Cards the you will need a 2D array

Card[][] myDecks = new Card[8][52];
// .. and initialise it all
0

You can also use an ArrayList<Deck>, or an ArrayList<ArrayList<Card>>. I like arrayLists because of the easy manipulation and editing of the contents.

ArrayList<Deck> deckAL= new ArrayList<Deck>();
for (int i = 0; i < 8; i++) {
   deckAL.add(new Deck(...));
}

Or:

ArrayList<ArrayList<Card>> cardAL= new ArrayList<ArrayList<Card>>();
for (int i = 0; i < 8; i++) {
   deckAL.add(new ArrayList<Card>());
}
for (ArrayList<Card> a: cardAL) {
   a.add(new Card(...));
}

Edited by hiddepolen: '1' instead of 'i'

0

^ yes.
For some bizarre reason teachers use a syllabus based on very traditional programming that insist on torturing students with naked arrays before letting them use any more useful collection classes. IMHO that's a distraction because they spend more time struggling with uninitialised array elements, trying to guess a size for the array, etc rather than thinking about algorithms and code structure.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.