Choosing a Design Method for Game Word Play
I am trying to create a simple application with a finished program that looks like this:
ladder game http://img199.imageshack.us/img199/6859/lab9a.jpg
I will also have to implement two different GUI layouts. Now I am trying to find the best method to accomplish this task. My professor told me to introduce an Element class with 4 states:
- empty
- invisible (used in GridLayout)
- first letter
- another letter
I thought about the following solutions (by the list I mean any collection):
1. An element is one letter, and each line is an Element []. The game class will be an array of arrays Element []. I think this is the dumbest way and checking can be troublesome.
2. As before, but Line is a list of items. The game is an array of strings.
3. As before, but Game is a list of strings.
Which one should you choose? Or maybe you have some ideas? Which collection would be better if you could use it?
a source to share
Your grid is your internal data model (i.e. no one but you will use it). That is why you can choose the one that is most convenient for you.
I would prefer the first solution with arrays, because the code would be a little more readable (at least for me). Just compare:
grid[3][4] = element;
and
grid.get(3).add(4, element);
Also, if you want to use collections, then you probably have to use
Map<Integer, List<Element>> grid
where Integer-key represents the index of the string. With a list of lists, it is very difficult to insert new words (just think about how you would implement this with just lists).
a source to share