Working with arrays of lists pattern in java
- by Mad Wombat
I am writing a card game in java where I need to spread cards from a deck into several columns until I have fixed amount of cards left. This is how I do this.
public class Column extends ArrayList {}
List deck = Cards.createNewDeck();
Column[] columns = new Column[10];
int c = 0;
while (deck.size() 50) {
if (c == 10) {
c = 0;
}
if (columns[c] == null) {
columns[c] = new Column();
}
columns[c].add(Cards.dealTopCard(deck));
c += 1;
}
This somehow seems clunky. Is there a more readable/comprehensive way of doing the same thing?