Choosing design method for ladder-like word game
I'm trying to build a simple application, with the finished program looking like this :
ladder-like game http://img199.imageshack.us/img199/6859/lab9a.jpg
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 letterI'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 ?
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).
精彩评论