views:

64

answers:

1

I'm trying to build a simple application, with the finished program looking like this :

ladder-like game

I will also have to implement two different GUI layouts for this. Now I'm trying to figure out the best method to perform this task. My professor told me to introduce Element class with 4 states :
- empty
- invisible (used in GridLayout)
- first letter
- other letter

I've thought about following solutions (by List I mean any sort of Collection) :
1. Element is a single letter, and each line is Element[]. Game class will be array of arrays Element[]. I guess that's the dumbest way, and the validation might be troublesome.
2. Like previously but Line is a List of Element. Game is an array of Lines.
3. Like previously but Game is a List of Lines.

Which one should I choose ? Or maybe do you have better ideas ? What collection would be best if to use one ?

+2  A: 

Your grid is your internal data model (i.e. none except for you will use it). That's why you can choose the one which is the most convinient for you.

I would prefer the first solution with arrays because the code will be a little more readable (at least for me). Just compare:

grid[3][4] = element;

and

grid.get(3).add(4, element);

Moreover, if you want to use collections, then you probably need to use

Map<Integer, List<Element>> grid

where Integer-key represents row index. With list of lists it's very difficult to insert new words (just think, how would you implement that with lists only).

Roman