# 为阶梯式文字游戏选择设计方法[英] Choosing design method for ladder-like word game

### 问题描述

- 空
- 隐形(用于Gridlayout)
- 首字母
- 其他字母

1.元素是一个字母，每行都是元素[].游戏类将是数组元素的数组[].我想那是最愚蠢的方法，验证可能很麻烦.
2.像以前一样，但行是元素的列表.游戏是一系列线条.
3.像以前一样，但游戏是行列表.

## 推荐答案

```grid[3][4] = element;
```

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

```Map<Integer, List<Element>> grid
```

integer-key表示索引.对于列表列表，很难插入新单词(只是想一想，您将如何仅使用列表实施).

### 问题描述

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 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 ?

## 推荐答案

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).