选择梯形文字游戏的设计方法 [英] Choosing design method for ladder-like word game

查看:126
本文介绍了选择梯形文字游戏的设计方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个简单的应用程序,完成的程序如下所示:

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

梯形游戏http://img199.imageshack.us/img199/6859/lab9a.jpg

我还将为此实现两种不同的GUI布局。现在我试图找出执行此任务的最佳方法。我的教授告诉我介绍Element类有4个州:

- 空

- 隐形(用于GridLayout)

- 第一个字母

- 其他信件

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

我已经考虑过以下解决方案(列表我的意思是任何类型的集合):

1.元素是单字母,每行都是Element []。游戏类将是数组元素[]。我猜这是最愚蠢的方式,验证可能会很麻烦。

2.像以前一样,但Line是元素列表。游戏是一系列的线条。

3.像以前一样,但游戏是线列表。

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;

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

此外,如果要使用集合,那么您可能需要使用

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

Map<Integer, List<Element>> grid

其中Integer-key表示行索引。列表列表很难插入新的单词(只是想想,你将如何实现与列表)。

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

这篇关于选择梯形文字游戏的设计方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆