Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm trying to make it so that no more than 5 units can be stacked on a tile. I have a Tile class that creates each tile's preferences. Should I store the units in an array or arraylist in this class?

share|improve this question
add comment

2 Answers

Choosing a data structure will depend on what other features you want to support. In this case, you may as well use the ArrayList since it's easier to work with and more flexible.

It would be best to just store a reference to the unit in the tile, and have the unit objects stored elsewhere.

share|improve this answer
4  
Up to 5 units is so trivial though. Either will do. –  Sidar Jan 13 '13 at 12:34
    
I agree @Sidar. I say ArrayList because it's much easier for a new developer to handle. With easy functions like add and remove. –  Byte56 Jan 13 '13 at 20:02
add comment

Based on the nature of your question a Stack http://docs.oracle.com/javase/6/docs/api/java/util/Stack.html be optimal, however it is last in first out so I don't know if that would fit your requirements, otherwise you could also use a queue. If order doesn't matter to you then use ArrayList, it is generally the most efficient (good comparison to linkedlist here http://www.java-gaming.org/topics/arraylist-vs-linkedlist/27017/view.html)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.