Skip to content
Advertisement

Need help on printing an Array of ArrayLists (of different sizes)

I’m making my own solitaire program I can run on my computer (for leisure and practice) and I am trying to display my ‘ArrayList<Card>[] playspace’ like it shows in Solitaire. More specifically I’m trying to display the card order downward instead of to the right side like it currently is. Following is my entire program (necessary classes needed to run).

This seemed to be a solution when I checked, but their issue was the bounds of the array and I don’t think they included the printing function, it is also not a 2D Array of ArrayLists… so it might be a solution but it looks just off enough to not be what I need.

Card:

JavaScript

Deck:

JavaScript

Wasp:

JavaScript

Playspace:

JavaScript

Main:

JavaScript

As it stands it prints like:

JavaScript

but I want it to print like: (Flipped along the line X = -Y)

JavaScript

Where each ArrayList is a column in an Array of 7. In the future (if I get a functional display, I would be removing the brackets around blank cards, simply having them in line with the columns as spaces, but one bridge at a time.

Advertisement

Answer

This isn’t super pretty, but it does the trick. I created a queue for each column and scanned through popping one element off of each to make a row. I had to put a spacer for the columns that had already run out of elements.

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement